~ubuntu-branches/ubuntu/vivid/python-reportlab/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/test_source_chars.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-01-12 02:16:21 UTC
  • mfrom: (1.2.9) (4.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140112021621-f4mpp5qaj1dkq2yb
Tags: 2.8~20140112-1
* New upstream snapshot.
* Build python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, SecureTestCase, GlobDirectoryWalker, printLocation
7
7
setOutDir(__name__)
8
8
from reportlab.lib.testutils import RL_HOME,testsFolder
9
 
__version__=''' $Id: test_source_chars.py 3959 2012-09-27 14:39:39Z robin $ '''
10
 
import os, sys, glob, string, re
11
 
from types import ModuleType, ClassType, MethodType, FunctionType
 
9
__version__=''' $Id$ '''
 
10
import os, sys, glob, re
12
11
import reportlab
13
12
import unittest
14
13
from reportlab.lib.utils import open_and_read
26
25
 
27
26
    def checkFileForTabs(self, filename):
28
27
        txt = open_and_read(filename, 'r')
29
 
        chunks = string.split(txt, '\t')
 
28
        chunks = txt.split('\t')
30
29
        tabCount = len(chunks) - 1
31
30
        if tabCount:
32
31
            #raise Exception, "File %s contains %d tab characters!" % (filename, tabCount)
37
36
        initSize = len(txt)
38
37
        badLines = 0
39
38
        badChars = 0
40
 
        for line in string.split(txt, '\n'):
41
 
            stripped = string.rstrip(line)
 
39
        for line in txt.split('\n'):
 
40
            stripped = line.rstrip()
42
41
            spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
43
42
            if spaces:
44
43
                badLines = badLines + 1
57
56
    """Eliminates trailing spaces IN PLACE.  Use with extreme care
58
57
    and only after a backup or with version-controlled code."""
59
58
    assert os.path.isdir(dirname), "Directory not found!"
60
 
    print "This will eliminate all trailing spaces in py files under %s." % dirname
61
 
    ok = raw_input("Shall I proceed?  type YES > ")
 
59
    print("This will eliminate all trailing spaces in py files under %s." % dirname)
 
60
    ok = input("Shall I proceed?  type YES > ")
62
61
    if ok != 'YES':
63
 
        print 'aborted by user'
 
62
        print('aborted by user')
64
63
        return
65
64
    w = GlobDirectoryWalker(dirname, '*.py')
66
65
    for filename in w:
68
67
        txt = open(filename, 'r').read()
69
68
        badChars = 0
70
69
        cleaned = []
71
 
        for line in string.split(txt, '\n'):
72
 
            stripped = string.rstrip(line)
 
70
        for line in txt.split('\n'):
 
71
            stripped = line.rstrip()
73
72
            cleaned.append(stripped)
74
73
            spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
75
74
            if spaces:
76
75
                badChars = badChars + spaces
77
76
 
78
77
        if badChars != 0:
79
 
            open(filename, 'w').write(string.join(cleaned, '\n'))
80
 
            print "file %s contained %d trailing spaces, FIXED" % (filename, badChars)
81
 
    print 'done'
 
78
            open(filename, 'w').write('\n'.join(cleaned))
 
79
            print("file %s contained %d trailing spaces, FIXED" % (filename, badChars))
 
80
    print('done')
82
81
 
83
82
def makeSuite():
84
83
    return makeSuiteForClasses(SourceTester)