1
1
"""some pylint test utilities
3
4
from glob import glob
4
from os.path import join, abspath, dirname, basename, exists
5
from os.path import join, abspath, dirname, basename, exists, splitext
5
6
from cStringIO import StringIO
7
8
from pylint.interfaces import IReporter
10
11
PREFIX = abspath(dirname(__file__))
14
14
sys.path.insert(0, PREFIX)
17
MSGPREFIXES = ['2.%s_'%i for i in range(5, 2, -1) if i <= sys.version_info[1]]
18
MSGPREFIXES.append('')
16
SYS_VERS_STR = '%d%d' % sys.version_info[:2]
20
def get_tests_info(prefix=None, suffix=None, inputdir='input', msgdir='messages'):
23
pattern = prefix + pattern
25
pattern = pattern + suffix
18
def get_tests_info(prefix, suffix):
19
"""get python input examples and output messages
21
We use following conventions for input files and messages:
23
don't test for python < x.y -> input = <name>_pyxy.py
24
don't test for python >= x.y -> input = <name>_py_xy.py
25
for one input and different messages:
26
message for python <= x.y -> message = <name>_pyxy.txt
27
higher versions -> message with highest num
27
for file in glob(join(PREFIX, inputdir, pattern)):
28
infile = basename(file)
29
for msgprefix in MSGPREFIXES:
30
outfile = join(PREFIX, msgdir, msgprefix + infile.replace(suffix, '.txt'))
30
for fname in glob(join(PREFIX, 'input', prefix + '*' + suffix)):
31
infile = basename(fname)
32
fbase = splitext(infile)[0]
33
# filter input files :
34
pyrestr = fbase.rsplit('_py', 1)[-1] # like _26 or 26
35
if pyrestr.isdigit(): # '24', '25'...
36
if SYS_VERS_STR < pyrestr:
38
if pyrestr.startswith('_') and pyrestr[1:].isdigit():
39
# skip test for higher python versions
40
if SYS_VERS_STR >= pyrestr[1:]:
42
messages = glob(join(PREFIX, 'messages', fbase + '*.txt'))
43
# the last one will be without ext, i.e. for all or upper versions:
45
for outfile in sorted(messages, reverse=True):
46
py_rest = outfile.rsplit('_py', 1)[-1][:-4]
47
if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
33
51
result.append((infile, outfile))
116
133
for attr, value in DEFAULTS.items():
117
134
setattr(self, attr, value)
119
class FileTC(unittest.TestCase):
136
class FileTC(TestCase):
120
137
"""base test case for testing file output"""
122
139
generated_files = ()
125
self.expected_files = [join('data', file)
142
self.expected_files = [join(dirname(abspath(__file__)), 'data', file)
126
143
for file in self.generated_files]
128
145
def tearDown(self):