[Python-checkins] cpython (3.2): #14492: fix some bugs in Tools/scripts/pdeps.py.

r.david.murray python-checkins at python.org
Fri Apr 6 05:01:28 CEST 2012


http://hg.python.org/cpython/rev/e9b8115c5b25
changeset: 76134:e9b8115c5b25
branch: 3.2
parent: 76130:acea9d95a6d8
user: R David Murray <rdmurray at bitdance.com>
date: Thu Apr 05 22:59:13 2012 -0400
summary:
 #14492: fix some bugs in Tools/scripts/pdeps.py.
Initial patch by Popa Claudiu.
files:
 Lib/test/test_tools.py | 27 +++++++++++++++++++++++++++
 Tools/scripts/pdeps.py | 10 +++++-----
 2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/Lib/test/test_tools.py b/Lib/test/test_tools.py
--- a/Lib/test/test_tools.py
+++ b/Lib/test/test_tools.py
@@ -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,31 @@
 import analyze_dxp
 
 
+class PdepsTests(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(self):
+ path = os.path.join(scriptsdir, 'pdeps.py')
+ self.pdeps = imp.load_source('pdeps', path)
+
+ @classmethod
+ def tearDownClass(self):
+ if 'pdeps' in sys.modules:
+ del sys.modules['pdeps']
+
+ def test_process_errors(self):
+ # Issue #14492: m_import.match(line) can be None.
+ with tempfile.TemporaryDirectory() as tmpdir:
+ fn = os.path.join(tmpdir, 'foo')
+ with open(fn, 'w') as stream:
+ stream.write("#!/this/will/fail")
+ self.pdeps.process(fn, {})
+
+ def test_inverse_attribute_error(self):
+ # Issue #14492: this used to fail with an AttributeError.
+ self.pdeps.inverse({'a': []})
+
+
 def test_main():
 support.run_unittest(*[obj for obj in globals().values()
 if isinstance(obj, type)])
diff --git a/Tools/scripts/pdeps.py b/Tools/scripts/pdeps.py
--- a/Tools/scripts/pdeps.py
+++ b/Tools/scripts/pdeps.py
@@ -76,10 +76,9 @@
 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
@@ -87,6 +86,7 @@
 word = word.strip()
 if word not in list:
 list.append(word)
+ fp.close()
 
 
 # Compute closure (this is in fact totally general)
@@ -123,7 +123,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)
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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