Gentoo Archives: gentoo-commits

From: "Arfrever Frehtes Taifersar Arahesis (arfrever)" <arfrever@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-python/pylint/files: pylint-0.18.1-utils.py.patch
Date: Fri, 04 Sep 2009 22:59:33
Message-Id: E1Mjhkh-0002Ld-R0@stork.gentoo.org
1 arfrever 09/09/04 22:59:31
2
3 Added: pylint-0.18.1-utils.py.patch
4 Log:
5 Fix tests.
6 (Portage version: 14182-svn/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 dev-python/pylint/files/pylint-0.18.1-utils.py.patch
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-python/pylint/files/pylint-0.18.1-utils.py.patch?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-python/pylint/files/pylint-0.18.1-utils.py.patch?rev=1.1&content-type=text/plain
13
14 Index: pylint-0.18.1-utils.py.patch
15 ===================================================================
16 test/utils.py from dev-python/pylint-0.18.0.
17
18 --- test/utils.py
19 +++ test/utils.py
20 @@ -0,0 +1,153 @@
21 +"""some pylint test utilities
22 +"""
23 +from glob import glob
24 +from os.path import join, abspath, dirname, basename, exists
25 +from cStringIO import StringIO
26 +
27 +from pylint.interfaces import IReporter
28 +from pylint.reporters import BaseReporter
29 +
30 +PREFIX = abspath(dirname(__file__))
31 +
32 +def fix_path():
33 + import sys
34 + sys.path.insert(0, PREFIX)
35 +
36 +import sys
37 +MSGPREFIXES = ['2.%s_'%i for i in range(5, 2, -1) if i <= sys.version_info[1]]
38 +MSGPREFIXES.append('')
39 +
40 +def get_tests_info(prefix=None, suffix=None, inputdir='input', msgdir='messages'):
41 + pattern = '*'
42 + if prefix:
43 + pattern = prefix + pattern
44 + if suffix:
45 + pattern = pattern + suffix
46 + result = []
47 + for file in glob(join(PREFIX, inputdir, pattern)):
48 + infile = basename(file)
49 + for msgprefix in MSGPREFIXES:
50 + outfile = join(PREFIX, msgdir, msgprefix + infile.replace(suffix, '.txt'))
51 + if exists(outfile):
52 + break
53 + result.append((infile, outfile))
54 + return result
55 +
56 +
57 +TITLE_UNDERLINES = ['', '=', '-', '.']
58 +
59 +class TestReporter(BaseReporter):
60 + """ store plain text messages
61 + """
62 +
63 + __implements____ = IReporter
64 +
65 + def __init__(self):
66 + self.message_ids = {}
67 + self.reset()
68 +
69 + def reset(self):
70 + self.out = StringIO()
71 + self.messages = []
72 +
73 + def add_message(self, msg_id, location, msg):
74 + """manage message of different type and in the context of path """
75 + fpath, module, object, line = location
76 + self.message_ids[msg_id] = 1
77 + if object:
78 + object = ':%s' % object
79 + sigle = msg_id[0]
80 + self.messages.append('%s:%3s%s: %s' % (sigle, line, object, msg))
81 +
82 + def finalize(self):
83 + self.messages.sort()
84 + for msg in self.messages:
85 + print >>self.out, msg
86 + result = self.out.getvalue()
87 + self.reset()
88 + return result
89 +
90 + def display_results(self, layout):
91 + """ignore layouts"""
92 +
93 +
94 +# # # # # pyreverse unittest utilities # # # # # #
95 +
96 +
97 +import unittest
98 +import os
99 +import sys
100 +from os.path import join
101 +
102 +from logilab.astng import MANAGER
103 +
104 +
105 +
106 +def _astng_wrapper(func, modname):
107 + return func(modname)
108 +
109 +
110 +def _sorted_file(path):
111 + lines = [line.strip() for line in open(path).readlines()
112 + if (line.find('squeleton generated by ') == -1 and
113 + not line.startswith('__revision__ = "$Id:'))]
114 + lines = [line for line in lines if line]
115 + lines.sort()
116 + return '\n'.join(lines)
117 +
118 +def get_project(module, name=None):
119 + """return a astng project representation
120 + """
121 + manager = MANAGER
122 + # flush cache
123 + manager._modules_by_name = {}
124 + return manager.project_from_files([module], _astng_wrapper,
125 + project_name=name)
126 +
127 +DEFAULTS = {'all_ancestors': None, 'show_associated': None,
128 + 'module_names': None,
129 + 'output_format': 'dot', 'diadefs_file': None, 'quiet': 0,
130 + 'show_ancestors': None, 'classes': (), 'all_associated': None,
131 + 'mode': 'PUB_ONLY', 'show_builtin': False, 'only_classnames': False}
132 +
133 +class Config(object):
134 + """config object for tests"""
135 + def __init__(self):
136 + for attr, value in DEFAULTS.items():
137 + setattr(self, attr, value)
138 +
139 +class FileTC(unittest.TestCase):
140 + """base test case for testing file output"""
141 +
142 + generated_files = ()
143 +
144 + def setUp(self):
145 + self.expected_files = [join('data', file)
146 + for file in self.generated_files]
147 +
148 + def tearDown(self):
149 + for fname in self.generated_files:
150 + try:
151 + os.remove(fname)
152 + except:
153 + continue
154 +
155 + def _test_same_file(self, index):
156 + generated_file = self.generated_files[index]
157 + expected_file = self.expected_files[index]
158 + generated = _sorted_file(generated_file)
159 + expected = _sorted_file(expected_file)
160 +
161 + from difflib import unified_diff
162 + files = "\n *** expected : %s, generated : %s \n" % (
163 + expected_file, generated_file)
164 + self.assertEqual(expected, generated, '%s%s' % (
165 + files, '\n'.join(line for line in unified_diff(
166 + expected.splitlines(), generated.splitlines() ))) )
167 + os.remove(generated_file)
168 +
169 +
170 +def build_file_case(filetc):
171 + for i in range(len(filetc.generated_files)):
172 + setattr(filetc, 'test_same_file_%s' %i,
173 + lambda self, index=i: self._test_same_file(index))