Skip to content

Commit

Permalink
Add Python test cases for Config.from_dict()
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Feb 23, 2024
1 parent b580745 commit 27425cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import reclass_rs
import pytest


def test_config_from_dict():
config_options = {
"nodes_uri": "targets",
"classes_uri": "classes",
"ignore_class_notfound": False,
"compose_node_name": False,
}
c = reclass_rs.Config.from_dict("./tests/inventory", config_options)
assert c is not None

assert not c.ignore_class_notfound
assert not c.compose_node_name

expected_nodes_path = pathlib.Path("./tests/inventory/targets")
expected_classes_path = pathlib.Path("./tests/inventory/classes")
assert pathlib.Path(c.nodes_path) == expected_nodes_path
assert pathlib.Path(c.classes_path) == expected_classes_path


def test_config_from_dict_non_default():
config_options = {
"nodes_uri": "targets",
"classes_uri": "classes",
"ignore_class_notfound": True,
"ignore_class_notfound_regexp": ["foo", "bar"],
"compose_node_name": True,
}
c = reclass_rs.Config.from_dict("./tests/inventory", config_options)
assert c is not None

assert c.ignore_class_notfound
assert c.compose_node_name

expected_nodes_path = pathlib.Path("./tests/inventory/targets")
expected_classes_path = pathlib.Path("./tests/inventory/classes")
assert pathlib.Path(c.nodes_path) == expected_nodes_path
assert pathlib.Path(c.classes_path) == expected_classes_path

assert c.ignore_class_notfound_regexp == ["foo", "bar"]

0 comments on commit 27425cd

Please sign in to comment.