diff -r 64b8fdb0bfa9 Lib/test/test_tools.py --- a/Lib/test/test_tools.py Thu Apr 05 06:42:48 2012 +0300 +++ b/Lib/test/test_tools.py Thu Apr 05 10:26:19 2012 +0300 @@ -6,8 +6,10 @@ import os import sys +import imp import unittest import sysconfig +import tempfile from test import support from test.script_helper import assert_python_ok @@ -72,6 +74,39 @@ import analyze_dxp +class PdepsTests(unittest.TestCase): + def setUp(self): + path = os.path.join(scriptsdir, 'pdeps.py') + self.pdeps = imp.load_source('pdeps', path) + + def tearDown(self): + if 'pdeps' in sys.modules: + del sys.modules['pdeps'] + + def test_process_errors(self): + """ + TypeError is raised in pdeps.process due to the fact that this line: + m_import.match(line)>= 0 + can be equivalent to None>= 0 if the match failed for that line. + """ + handle, path = tempfile.mkstemp() + os.close(handle) + with open(path, 'w') as stream: + stream.write("#!/this/will/fail") + + try: + self.pdeps.process(path, {}) + except TypeError: + self.fail("pdeps.py process failed with TypeError") + finally: + os.remove(path) + + def test_inverse_attribute_error(self): + try: + self.pdeps.inverse({'a':[]}) + except AttributeError: + self.fail("pdeps.py inverse failed with AttributeError") + def test_main(): support.run_unittest(*[obj for obj in globals().values() if isinstance(obj, type)]) diff -r 64b8fdb0bfa9 Tools/scripts/pdeps.py --- a/Tools/scripts/pdeps.py Thu Apr 05 06:42:48 2012 +0300 +++ b/Tools/scripts/pdeps.py Thu Apr 05 10:26:19 2012 +0300 @@ -64,7 +64,7 @@ # Collect data from one file # def process(filename, table): - fp = open(filename, 'r') + fp = open(filename, 'r') mod = os.path.basename(filename) if mod[-3:] == '.py': mod = mod[:-3] @@ -76,17 +76,18 @@ nextline = fp.readline() if not nextline: break line = line[:-1] + nextline - if m_import.match(line)>= 0: - (a, b), (a1, b1) = m_import.regs[:2] - elif m_from.match(line)>= 0: - (a, b), (a1, b1) = m_from.regs[:2] + + m_found = m_import.match(line) or m_from.match(line) + if m_found: + (a, b), (a1, b1) = m_found.regs[:2] else: continue words = line[a1:b1].split(',') # print '#', line, words for word in words: word = word.strip() if word not in list: - list.append(word) + list.append(word) + fp.close() # Compute closure (this is in fact totally general) @@ -123,7 +124,7 @@ def inverse(table): inv = {} for key in table.keys(): - if not inv.has_key(key): + if key not in inv: inv[key] = [] for item in table[key]: store(inv, item, key)

AltStyle によって変換されたページ (->オリジナル) /