Skip to content

Commit 04275bf

Browse files
committed
Fix for loading nodes when their module is not in the pythonpath at the time of loading it
1 parent c58056f commit 04275bf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

flowpipe/utilities.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def import_class(module, cls_name, file_location=None):
1919
module = importlib.import_module(module)
2020
except NameError: # pragma: no cover
2121
module = __import__(module, globals(), locals(), ["object"], -1)
22+
except ModuleNotFoundError: # pragma: no cover
23+
pass # this exception will be ignored to force the Source File load further down
2224
try:
2325
cls = getattr(module, cls_name)
2426
except AttributeError: # pragma: no cover

tests/test_utilities.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import sys
66
from hashlib import sha256
77

8+
import mock
89
import numpy as np
910

1011
import flowpipe.utilities as util
12+
from flowpipe import INode
1113

1214

1315
class WeirdObject(object):
@@ -93,3 +95,15 @@ def test_sanitize_string():
9395
expected_string = "This is a {{test}} string"
9496
sanitized_string = util.sanitize_string_input(test_string)
9597
assert sanitized_string == expected_string
98+
99+
100+
class NodeInTest(INode):
101+
""""""
102+
103+
104+
@mock.patch("importlib.import_module", side_effect=ModuleNotFoundError)
105+
def test_import_class_from_current_file(_):
106+
cls = util.import_class(
107+
"test_utilities", "NodeInTest", file_location=__file__
108+
)
109+
assert cls.__name__ == NodeInTest.__name__

0 commit comments

Comments
 (0)