Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/objdictgen/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ def DumpFile(self, filepath: TPath, filetype: str|None = "jsonc", custom_genfile

if custom_genfile != None:
Comment thread
LM-robynka marked this conversation as resolved.
Outdated
log.debug("Invoking custom generator: %s", custom_genfile)
return executeCustomGenerator(custom_genfile, filepath, self)
try:
return executeCustomGenerator(custom_genfile, filepath, self)
except (ImportError, ModuleNotFoundError):
log.debug("Failed to load custom generator: %s", custom_genfile)
Comment thread
LM-robynka marked this conversation as resolved.

if filetype == 'c':
log.debug("Writing C files '%s'", filepath)
Expand Down
17 changes: 16 additions & 1 deletion tests/test_node.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
"""Tests for node.py"""
import pytest
import os

from objdictgen.node import Node
from objdictgen.node import Node, NodeProtocol, executeCustomGenerator

@pytest.mark.parametrize("file", ['master', 'slave'])
def test_node_LoadFile(odpath, file):

od = Node.LoadFile(odpath / (file + '.json'))
assert isinstance(od, Node)
assert od.Name == 'master' if file == 'master' else 'slave'

@pytest.mark.parametrize("filename", ["this_file_does_not_exist.py", "bad_generator.py", "generator.py"])
def test_node_execute_custom_generator(filename: str):
print(os.getcwd())
full_path = "tests/test_generators/"
mock_path = "/mock"
Comment thread
LM-robynka marked this conversation as resolved.
if filename == "bad_generator.py":
with pytest.raises(AttributeError):
executeCustomGenerator(full_path + filename, mock_path, NodeProtocol)
elif filename == "this_file_does_not_exist.py":
with pytest.raises(FileNotFoundError):
executeCustomGenerator(full_path + filename, mock_path, NodeProtocol)
elif filename == "generator.py":
assert executeCustomGenerator(full_path + filename, mock_path, NodeProtocol) == "success"
Loading