<s> import __future__ <EOL> import os <EOL> import unittest <EOL> import distutils . dir_util <EOL> import tempfile <EOL> from test import test_support <EOL> try : set <EOL> except NameError : from sets import Set as set <EOL> import modulefinder <EOL> TEST_DIR = tempfile . mkdtemp ( ) <EOL> TEST_PATH = [ TEST_DIR , os . path . dirname ( __future__ . __file__ ) ] <EOL> maybe_test = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:b>" ] , <EOL> [ "<STR_LIT:c>" ] , [ "<STR_LIT>" ] , <EOL> """<STR_LIT>""" ] <EOL> maybe_test_new = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:b>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT:c>" ] , [ "<STR_LIT>" ] , <EOL> """<STR_LIT>""" ] <EOL> package_test = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , [ ] , <EOL> """<STR_LIT>""" ] <EOL> absolute_import_test = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" , <EOL> "<STR_LIT:b>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , [ ] , <EOL> """<STR_LIT>""" ] <EOL> relative_import_test = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT:a>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] , <EOL> [ ] , [ ] , <EOL> """<STR_LIT>""" ] <EOL> relative_import_test_2 = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] , <EOL> [ ] , [ ] , <EOL> """<STR_LIT>""" ] <EOL> relative_import_test_3 = [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT:a>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ ] , <EOL> """<STR_LIT>""" ] <EOL> def open_file ( path ) : <EOL> dirname = os . path . dirname ( path ) <EOL> distutils . dir_util . mkpath ( dirname ) <EOL> return open ( path , "<STR_LIT:w>" ) <EOL> def create_package ( source ) : <EOL> ofi = None <EOL> try : <EOL> for line in source . splitlines ( ) : <EOL> if line . startswith ( "<STR_LIT:U+0020>" ) or line . startswith ( "<STR_LIT:\t>" ) : <EOL> ofi . write ( line . strip ( ) + "<STR_LIT:\n>" ) <EOL> else : <EOL> if ofi : <EOL> ofi . close ( ) <EOL> ofi = open_file ( os . path . join ( TEST_DIR , line . strip ( ) ) ) <EOL> finally : <EOL> if ofi : <EOL> ofi . close ( ) <EOL> class ModuleFinderTest ( unittest . TestCase ) : <EOL> def _do_test ( self , info , report = False ) : <EOL> import_this , modules , missing , maybe_missing , source = info <EOL> create_package ( source ) <EOL> try : <EOL> mf = modulefinder . ModuleFinder ( path = TEST_PATH ) <EOL> mf . import_hook ( import_this ) <EOL> if report : <EOL> mf . report ( ) <EOL> modules = set ( modules ) <EOL> found = set ( mf . modules . keys ( ) ) <EOL> more = list ( found - modules ) <EOL> less = list ( modules - found ) <EOL> self . assertEqual ( ( more , less ) , ( [ ] , [ ] ) ) <EOL> bad , maybe = mf . any_missing_maybe ( ) <EOL> self . assertEqual ( bad , missing ) <EOL> self . assertEqual ( maybe , maybe_missing ) <EOL> finally : <EOL> distutils . dir_util . remove_tree ( TEST_DIR ) <EOL> def test_package ( self ) : <EOL> self . _do_test ( package_test ) <EOL> def test_maybe ( self ) : <EOL> self . _do_test ( maybe_test ) <EOL> if getattr ( __future__ , "<STR_LIT>" , None ) : <EOL> def test_maybe_new ( self ) : <EOL> self . _do_test ( maybe_test_new ) <EOL> def test_absolute_imports ( self ) : <EOL> self . _do_test ( absolute_import_test ) <EOL> def test_relative_imports ( self ) : <EOL> self . _do_test ( relative_import_test ) <EOL> def test_relative_imports_2 ( self ) : <EOL> self . _do_test ( relative_import_test_2 ) <EOL> def test_relative_imports_3 ( self ) : <EOL> self . _do_test ( relative_import_test_3 ) <EOL> def test_main ( ) : <EOL> distutils . log . set_threshold ( distutils . log . WARN ) <EOL> test_support . run_unittest ( ModuleFinderTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
