1- import __future__
21import os
2+ import errno
3+ import shutil
34import unittest
4- import distutils .dir_util
55import tempfile
66
77from test import support
88
99import modulefinder
1010
1111TEST_DIR = tempfile .mkdtemp ()
12- TEST_PATH = [TEST_DIR , os .path .dirname (__future__ .__file__ )]
12+ TEST_PATH = [TEST_DIR , os .path .dirname (tempfile .__file__ )]
1313
1414# Each test description is a list of 5 items:
1515#
@@ -196,12 +196,17 @@ def foo(): pass
196196 from . import bar
197197""" ]
198198
199+
199200def open_file (path ):
200- ##print "#", os.path.abspath(path)
201201 dirname = os .path .dirname (path )
202- distutils .dir_util .mkpath (dirname )
202+ try :
203+ os .makedirs (dirname )
204+ except OSError as e :
205+ if e .errno != errno .EEXIST :
206+ raise
203207 return open (path , "w" )
204208
209+
205210def create_package (source ):
206211 ofi = None
207212 try :
@@ -216,6 +221,7 @@ def create_package(source):
216221 if ofi :
217222 ofi .close ()
218223
224+
219225class ModuleFinderTest (unittest .TestCase ):
220226 def _do_test (self , info , report = False ):
221227 import_this , modules , missing , maybe_missing , source = info
@@ -234,45 +240,41 @@ def _do_test(self, info, report=False):
234240## import traceback; traceback.print_exc()
235241## sys.path = opath
236242## return
237- modules = set (modules )
238- found = set (mf .modules .keys ())
239- more = list (found - modules )
240- less = list (modules - found )
243+ modules = sorted (set (modules ))
244+ found = sorted (mf .modules )
241245 # check if we found what we expected, not more, not less
242- self .assertEqual (( more , less ), ([], []) )
246+ self .assertEqual (found , modules )
243247
244248 # check for missing and maybe missing modules
245249 bad , maybe = mf .any_missing_maybe ()
246250 self .assertEqual (bad , missing )
247251 self .assertEqual (maybe , maybe_missing )
248252 finally :
249- distutils . dir_util . remove_tree (TEST_DIR )
253+ shutil . rmtree (TEST_DIR )
250254
251255 def test_package (self ):
252256 self ._do_test (package_test )
253257
254258 def test_maybe (self ):
255259 self ._do_test (maybe_test )
256260
257- if getattr (__future__ , "absolute_import" , None ):
261+ def test_maybe_new (self ):
262+ self ._do_test (maybe_test_new )
258263
259- def test_maybe_new (self ):
260- self ._do_test (maybe_test_new )
264+ def test_absolute_imports (self ):
265+ self ._do_test (absolute_import_test )
261266
262- def test_absolute_imports (self ):
263- self ._do_test (absolute_import_test )
267+ def test_relative_imports (self ):
268+ self ._do_test (relative_import_test )
264269
265- def test_relative_imports (self ):
266- self ._do_test (relative_import_test )
270+ def test_relative_imports_2 (self ):
271+ self ._do_test (relative_import_test_2 )
267272
268- def test_relative_imports_2 (self ):
269- self ._do_test (relative_import_test_2 )
273+ def test_relative_imports_3 (self ):
274+ self ._do_test (relative_import_test_3 )
270275
271- def test_relative_imports_3 (self ):
272- self ._do_test (relative_import_test_3 )
273276
274277def test_main ():
275- distutils .log .set_threshold (distutils .log .WARN )
276278 support .run_unittest (ModuleFinderTest )
277279
278280if __name__ == "__main__" :
0 commit comments