Skip to content

Commit 109ddc0

Browse files
committed
[tests] Add test to reload plugins with syntax errors in the description
1 parent f268ba1 commit 109ddc0

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tests/test_plugins.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_loadedPlugin(self):
158158
assert name == "sharedTemplate"
159159
assert plugin.templates[name] == os.path.join(str(plugin.path), "sharedTemplate.mg")
160160

161-
def test_reloadNodePlugin(self):
161+
def test_reloadNodePluginInvalidDescrpition(self):
162162
plugin = pluginManager.getPlugin("pluginB")
163163
assert plugin == self.plugin
164164
node = plugin.nodes["PluginBNodeB"]
@@ -217,6 +217,39 @@ def test_reloadNodePlugin(self):
217217
assert node.status == NodePluginStatus.DESC_ERROR # Not NOT_LOADED
218218
assert not pluginManager.isRegistered(nodeName)
219219

220+
def test_reloadNodePluginSyntaxError(self):
221+
plugin = pluginManager.getPlugin("pluginB")
222+
assert plugin == self.plugin
223+
node = plugin.nodes["PluginBNodeA"]
224+
nodeName = node.nodeDescriptor.__name__
225+
226+
# Check that the node has been registered
227+
assert node.status == NodePluginStatus.LOADED
228+
assert pluginManager.isRegistered(nodeName)
229+
230+
# Introduce a syntax error in the description
231+
originalFileContent = None
232+
with open(node.path, "r") as f:
233+
originalFileContent = f.read()
234+
235+
replaceFileContent = originalFileContent.replace('name="input",', 'name="input"')
236+
with open(node.path, "w") as f:
237+
f.write(replaceFileContent)
238+
239+
# Reload the node and assert it is invalid but still registered
240+
node.reload()
241+
assert node.status == NodePluginStatus.DESC_ERROR
242+
assert pluginManager.isRegistered(nodeName)
243+
244+
# Restore the node file to its original state (with a description error)
245+
with open(node.path, "w") as f:
246+
f.write(originalFileContent)
247+
248+
# Assert the status is correct and the node is still registered
249+
node.reload()
250+
assert node.status == NodePluginStatus.NOT_LOADED
251+
assert pluginManager.isRegistered(nodeName)
252+
220253

221254
class TestPluginsConfiguration:
222255
CONFIG_PATH = ("CONFIG_PATH", "sharedTemplate.mg", "config.json")

0 commit comments

Comments
 (0)