File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def get_filename(self, fullname: str) -> str:
59
59
60
60
def create_module (self , spec : importlib .machinery .ModuleSpec ):
61
61
mod = types .ModuleType (spec .name )
62
+ mod .__file__ = spec .loader_state ["filename" ]
62
63
mod .__loader__ = spec .loader
63
64
mod .__package__ = spec .parent
64
65
mod .__spec__ = spec
@@ -103,4 +104,6 @@ def hook_imports():
103
104
104
105
Once this is called, Basilisp code may be called from within Python code
105
106
using standard `import module.submodule` syntax."""
107
+ if any ([isinstance (o , BasilispImporter ) for o in sys .meta_path ]):
108
+ return
106
109
sys .meta_path .insert (0 , BasilispImporter ()) # pylint:disable=abstract-class-instantiated
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from unittest .mock import patch
3
+
4
+ import basilisp .importer as importer
5
+
6
+
7
+ def importer_counter ():
8
+ return sum ([isinstance (o , importer .BasilispImporter ) for o in sys .meta_path ])
9
+
10
+
11
+ def test_hook_imports ():
12
+ with patch ('sys.meta_path' ,
13
+ new = []):
14
+ assert 0 == importer_counter ()
15
+ importer .hook_imports ()
16
+ assert 1 == importer_counter ()
17
+ importer .hook_imports ()
18
+ assert 1 == importer_counter ()
19
+
20
+ with patch ('sys.meta_path' ,
21
+ new = [importer .BasilispImporter ()]):
22
+ assert 1 == importer_counter ()
23
+ importer .hook_imports ()
24
+ assert 1 == importer_counter ()
You can’t perform that action at this time.
0 commit comments