tests/test_source_chars.py
branchpy33
changeset 3794 398ea04239b5
parent 3721 0c93dd8ff567
child 3803 e2bd2e9f0b3e
equal deleted inserted replaced
3793:cc3f9cc828f7 3794:398ea04239b5
     5 """
     5 """
     6 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, SecureTestCase, GlobDirectoryWalker, printLocation
     6 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, SecureTestCase, GlobDirectoryWalker, printLocation
     7 setOutDir(__name__)
     7 setOutDir(__name__)
     8 from reportlab.lib.testutils import RL_HOME,testsFolder
     8 from reportlab.lib.testutils import RL_HOME,testsFolder
     9 __version__=''' $Id$ '''
     9 __version__=''' $Id$ '''
    10 import os, sys, glob, string, re
    10 import os, sys, glob, re
    11 from types import ModuleType, ClassType, MethodType, FunctionType
    11 from types import ModuleType, ClassType, MethodType, FunctionType
    12 import reportlab
    12 import reportlab
    13 import unittest
    13 import unittest
    14 from reportlab.lib.utils import open_and_read
    14 from reportlab.lib.utils import open_and_read
    15 
    15 
    24 
    24 
    25         self.output = open(outputfile(os.path.splitext(os.path.basename(fn))[0]+'.txt'),'w')
    25         self.output = open(outputfile(os.path.splitext(os.path.basename(fn))[0]+'.txt'),'w')
    26 
    26 
    27     def checkFileForTabs(self, filename):
    27     def checkFileForTabs(self, filename):
    28         txt = open_and_read(filename, 'r')
    28         txt = open_and_read(filename, 'r')
    29         chunks = string.split(txt, '\t')
    29         chunks = txt.split('\t')
    30         tabCount = len(chunks) - 1
    30         tabCount = len(chunks) - 1
    31         if tabCount:
    31         if tabCount:
    32             #raise Exception, "File %s contains %d tab characters!" % (filename, tabCount)
    32             #raise Exception, "File %s contains %d tab characters!" % (filename, tabCount)
    33             self.output.write("file %s contains %d tab characters!\n" % (filename, tabCount))
    33             self.output.write("file %s contains %d tab characters!\n" % (filename, tabCount))
    34 
    34 
    35     def checkFileForTrailingSpaces(self, filename):
    35     def checkFileForTrailingSpaces(self, filename):
    36         txt = open_and_read(filename, 'r')
    36         txt = open_and_read(filename, 'r')
    37         initSize = len(txt)
    37         initSize = len(txt)
    38         badLines = 0
    38         badLines = 0
    39         badChars = 0
    39         badChars = 0
    40         for line in string.split(txt, '\n'):
    40         for line in txt.split('\n'):
    41             stripped = string.rstrip(line)
    41             stripped = line.rstrip()
    42             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
    42             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
    43             if spaces:
    43             if spaces:
    44                 badLines = badLines + 1
    44                 badLines = badLines + 1
    45                 badChars = badChars + spaces
    45                 badChars = badChars + spaces
    46 
    46 
    66     for filename in w:
    66     for filename in w:
    67         # trim off final newline and detect real changes
    67         # trim off final newline and detect real changes
    68         txt = open(filename, 'r').read()
    68         txt = open(filename, 'r').read()
    69         badChars = 0
    69         badChars = 0
    70         cleaned = []
    70         cleaned = []
    71         for line in string.split(txt, '\n'):
    71         for line in txt.split('\n'):
    72             stripped = string.rstrip(line)
    72             stripped = line.rstrip()
    73             cleaned.append(stripped)
    73             cleaned.append(stripped)
    74             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
    74             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
    75             if spaces:
    75             if spaces:
    76                 badChars = badChars + spaces
    76                 badChars = badChars + spaces
    77 
    77 
    78         if badChars != 0:
    78         if badChars != 0:
    79             open(filename, 'w').write(string.join(cleaned, '\n'))
    79             open(filename, 'w').write('\n'.join(cleaned))
    80             print("file %s contained %d trailing spaces, FIXED" % (filename, badChars))
    80             print("file %s contained %d trailing spaces, FIXED" % (filename, badChars))
    81     print('done')
    81     print('done')
    82 
    82 
    83 def makeSuite():
    83 def makeSuite():
    84     return makeSuiteForClasses(SourceTester)
    84     return makeSuiteForClasses(SourceTester)