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