Python files and ascii
Claude Paroz <[email protected]> Fri, 18 Feb 2022 23:45:38 +0100
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <[email protected]> |
Hi all, Here's a new patch that stop testing for ReportLab Python files being ASCII-only. On Python 3, we can safely include Unicode chars in Python files. Claude -- www.2xlibre.net
0001-Stop-enforcing-ascii-only-python-files.patch
(text/x-patch, 3.4 KB)
From b250b66c39123a44d253f83a88d29e7f30587bfe Mon Sep 17 00:00:00 2001 From: Claude Paroz <[email protected]> Date: Fri, 18 Feb 2022 23:40:53 +0100 Subject: [PATCH] Stop enforcing ascii-only python files --- tests/test_pyfiles.py | 78 ++----------------------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/tests/test_pyfiles.py b/tests/test_pyfiles.py index 1ed79aa5..051ca1a6 100644 --- a/tests/test_pyfiles.py +++ b/tests/test_pyfiles.py @@ -5,81 +5,9 @@ __version__='3.3.0' """ from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, SecureTestCase, GlobDirectoryWalker, outputfile, printLocation setOutDir(__name__) -import os, sys, string, fnmatch, re +import os, string, re import unittest -from reportlab.lib.utils import open_and_read, open_and_readlines - -# Helper function and class. -def unique(seq): - "Remove elements from a list that occur more than once." - - # Return input if it has less than 2 elements. - if len(seq) < 2: - return seq - - # Make a sorted copy of the input sequence. - cnvt = isinstance(seq,str) - seq2 = seq[:] - if cnvt: seq2 = list(seq2) - seq2.sort() - - # Remove adjacent elements if they are identical. - i = 0 - while i < len(seq2)-1: - elem = seq2[i] - try: - while elem == seq2[i+1]: - del seq2[i+1] - except IndexError: - pass - i += 1 - - # Try to return something of the same type as the input. - if cnvt: - return seq[0:0].join(seq2) - else: - return seq2 - -class SelfTestCase(unittest.TestCase): - "Test unique() function." - - def testUnique(self): - "Test unique() function." - - cases = [([], []), - ([0], [0]), - ([0, 1, 2], [0, 1, 2]), - ([2, 1, 0], [0, 1, 2]), - ([0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 2, 3]), - ('abcabcabc', 'abc') - ] - - msg = "Failed: unique(%s) returns %s instead of %s." - for sequence, expectedOutput in cases: - output = unique(sequence) - args = (sequence, output, expectedOutput) - assert output == expectedOutput, msg % args - - -class AsciiFileTestCase(unittest.TestCase): - "Test if Python files are pure ASCII ones." - - def testAscii(self): - "Test if Python files are pure ASCII ones." - from reportlab.lib.testutils import RL_HOME - allPyFiles = GlobDirectoryWalker(RL_HOME, '*.py') - - for path in allPyFiles: - fileContent = open_and_read(path,'r') - nonAscii = [c for c in fileContent if ord(c)>127] - nonAscii = unique(nonAscii) - - truncPath = path[path.find('reportlab'):] - args = (truncPath, repr(list(map(ord, nonAscii)))) - msg = "File %s contains characters: %s." % args -## if nonAscii: -## print msg - assert not nonAscii, msg +from reportlab.lib.utils import open_and_readlines class FilenameTestCase(unittest.TestCase): @@ -140,7 +68,7 @@ class FirstLineTestCase(SecureTestCase): file.close() def makeSuite(): - suite = makeSuiteForClasses(SelfTestCase, AsciiFileTestCase, FilenameTestCase) + suite = makeSuiteForClasses(FilenameTestCase) loader = unittest.TestLoader() suite.addTest(loader.loadTestsFromTestCase(FirstLineTestCase)) return suite -- 2.30.2