File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1169,6 +1169,26 @@ def test_already_imported_custom_file_no_suggestions(self):
11691169 self .assertEqual (output , "import mymodule." )
11701170 del sys .modules ["mymodule" ]
11711171
1172+ def test_already_imported_module_without_origin_or_spec (self ):
1173+ with (tempfile .TemporaryDirectory () as _dir1 ,
1174+ patch .object (sys , "path" , [_dir1 , * sys .path ])):
1175+ dir1 = pathlib .Path (_dir1 )
1176+ for mod in ("no_origin" , "no_spec" ):
1177+ (dir1 / mod ).mkdir ()
1178+ (dir1 / mod / "__init__.py" ).touch ()
1179+ (dir1 / mod / "foo.py" ).touch ()
1180+ module = importlib .import_module (mod )
1181+ assert module .__spec__
1182+ if mod == "no_origin" :
1183+ module .__spec__ .origin = None
1184+ else :
1185+ module .__spec__ = None
1186+ events = code_to_events (f"import { mod } .\t \n " )
1187+ reader = self .prepare_reader (events , namespace = {})
1188+ output = reader .readline ()
1189+ self .assertEqual (output , f"import { mod } ." )
1190+ del sys .modules [mod ]
1191+
11721192 def test_get_path_and_prefix (self ):
11731193 cases = (
11741194 ('' , ('' , '' )),
You can’t perform that action at this time.
0 commit comments