#NEWLINE# def test_update_imports_inserts_initial_imports( index ) : #NEWLINE# #INDENT# src = dedent ( "\n        print(os.path.basename('sys/foo'))\n        print(sys.path[0])\n        print(basename('sys/foo'))\n        print(path.basename('sys/foo'))\n        " ) . strip ( ) #NEWLINE# ( unresolved , unreferenced ) = Scope . from_source ( src ) . find_unresolved_and_unreferenced_symbols ( ) #NEWLINE# assert ( unresolved == set ( [ 'os.path.basename' , 'sys.path' , 'basename' , 'path.basename' ] ) ) #NEWLINE# new_src = update_imports ( src , index , unresolved , unreferenced ) #NEWLINE# assert ( dedent ( "\n        import os.path\n        import sys\n        from os import path\n        from os.path import basename\n\n\n        print(os.path.basename('sys/foo'))\n        print(sys.path[0])\n        print(basename('sys/foo'))\n        print(path.basename('sys/foo'))\n        " ) . strip ( ) == new_src . strip ( ) )