diff options
Diffstat (limited to 'test/utils.py')
-rw-r--r-- | test/utils.py | 90 |
1 files changed, 1 insertions, 89 deletions
diff --git a/test/utils.py b/test/utils.py index e1b5c3c..4060625 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1,100 +1,12 @@ """some pylint test utilities """ -import sys -from glob import glob -from os.path import join, abspath, dirname, basename, exists, splitext -from cStringIO import StringIO - -from pylint.interfaces import IReporter -from pylint.reporters import BaseReporter - -PREFIX = abspath(dirname(__file__)) - -def fix_path(): - sys.path.insert(0, PREFIX) - -SYS_VERS_STR = '%d%d' % sys.version_info[:2] - -def get_tests_info(prefix, suffix): - """get python input examples and output messages - - We use following conventions for input files and messages: - for different inputs: - don't test for python < x.y -> input = <name>_pyxy.py - don't test for python >= x.y -> input = <name>_py_xy.py - for one input and different messages: - message for python <= x.y -> message = <name>_pyxy.txt - higher versions -> message with highest num - """ - result = [] - for fname in glob(join(PREFIX, 'input', prefix + '*' + suffix)): - infile = basename(fname) - fbase = splitext(infile)[0] - # filter input files : - pyrestr = fbase.rsplit('_py', 1)[-1] # like _26 or 26 - if pyrestr.isdigit(): # '24', '25'... - if SYS_VERS_STR < pyrestr: - continue - if pyrestr.startswith('_') and pyrestr[1:].isdigit(): - # skip test for higher python versions - if SYS_VERS_STR >= pyrestr[1:]: - continue - messages = glob(join(PREFIX, 'messages', fbase + '*.txt')) - # the last one will be without ext, i.e. for all or upper versions: - if messages: - for outfile in sorted(messages, reverse=True): - py_rest = outfile.rsplit('_py', 1)[-1][:-4] - if py_rest.isdigit() and SYS_VERS_STR >= py_rest: - break - else: - outfile = None - result.append((infile, outfile)) - return result - - -TITLE_UNDERLINES = ['', '=', '-', '.'] - -class TestReporter(BaseReporter): - """ store plain text messages - """ - - __implements____ = IReporter - - def __init__(self): - self.message_ids = {} - self.reset() - - def reset(self): - self.out = StringIO() - self.messages = [] - - def add_message(self, msg_id, location, msg): - """manage message of different type and in the context of path """ - fpath, module, object, line, _ = location - self.message_ids[msg_id] = 1 - if object: - object = ':%s' % object - sigle = msg_id[0] - self.messages.append('%s:%3s%s: %s' % (sigle, line, object, msg)) - - def finalize(self): - self.messages.sort() - for msg in self.messages: - print >>self.out, msg - result = self.out.getvalue() - self.reset() - return result - - def display_results(self, layout): - """ignore layouts""" - # # # # # pyreverse unittest utilities # # # # # # from logilab.common.testlib import TestCase import os import sys -from os.path import join +from os.path import join, dirname, abspath from logilab.astng import MANAGER |