File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77import os
88import sys
9+ import imp
910import unittest
1011import sysconfig
12+ import tempfile
1113from test import support
1214from test .script_helper import assert_python_ok
1315
@@ -72,6 +74,31 @@ def test_analyze_dxp_import(self):
7274 import analyze_dxp
7375
7476
77+ class PdepsTests (unittest .TestCase ):
78+
79+ @classmethod
80+ def setUpClass (self ):
81+ path = os .path .join (scriptsdir , 'pdeps.py' )
82+ self .pdeps = imp .load_source ('pdeps' , path )
83+
84+ @classmethod
85+ def tearDownClass (self ):
86+ if 'pdeps' in sys .modules :
87+ del sys .modules ['pdeps' ]
88+
89+ def test_process_errors (self ):
90+ # Issue #14492: m_import.match(line) can be None.
91+ with tempfile .TemporaryDirectory () as tmpdir :
92+ fn = os .path .join (tmpdir , 'foo' )
93+ with open (fn , 'w' ) as stream :
94+ stream .write ("#!/this/will/fail" )
95+ self .pdeps .process (fn , {})
96+
97+ def test_inverse_attribute_error (self ):
98+ # Issue #14492: this used to fail with an AttributeError.
99+ self .pdeps .inverse ({'a' : []})
100+
101+
75102def test_main ():
76103 support .run_unittest (* [obj for obj in globals ().values ()
77104 if isinstance (obj , type )])
Original file line number Diff line number Diff line change @@ -76,17 +76,17 @@ def process(filename, table):
7676 nextline = fp .readline ()
7777 if not nextline : break
7878 line = line [:- 1 ] + nextline
79- if m_import .match (line ) >= 0 :
80- (a , b ), (a1 , b1 ) = m_import .regs [:2 ]
81- elif m_from .match (line ) >= 0 :
82- (a , b ), (a1 , b1 ) = m_from .regs [:2 ]
79+ m_found = m_import .match (line ) or m_from .match (line )
80+ if m_found :
81+ (a , b ), (a1 , b1 ) = m_found .regs [:2 ]
8382 else : continue
8483 words = line [a1 :b1 ].split (',' )
8584 # print '#', line, words
8685 for word in words :
8786 word = word .strip ()
8887 if word not in list :
8988 list .append (word )
89+ fp .close ()
9090
9191
9292# Compute closure (this is in fact totally general)
@@ -123,7 +123,7 @@ def closure(table):
123123def inverse (table ):
124124 inv = {}
125125 for key in table .keys ():
126- if not inv . has_key ( key ) :
126+ if key not in inv :
127127 inv [key ] = []
128128 for item in table [key ]:
129129 store (inv , item , key )
You can’t perform that action at this time.
0 commit comments