Skip to content

Commit

Permalink
Add setter for ignore_class_notfound_regexp() in the Python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Feb 20, 2024
1 parent 7973d58 commit d2d8ba4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ impl Reclass {
.collect::<HashMap<String, PathBuf>>();
Ok(res)
}

/// Update the current Reclass instance's config object with the provided
/// `ignore_class_notfound_regexp` patterns
pub fn set_ignore_class_notfound_regexp(&mut self, patterns: Vec<String>) -> PyResult<()> {
self.config
.set_ignore_class_notfound_regexp(patterns)
.map_err(|e| {
PyValueError::new_err(format!(
"Error while setting ignore_class_notfound_regexp: {e}"
))
})
}
}

impl Default for Reclass {
Expand Down
13 changes: 12 additions & 1 deletion tests/test_ignore_class_notfound_regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_ignore_regexp_render_n1():
assert n1 is not None


def test_ignore_regexp_render_n1():
def test_ignore_regexp_render_n2():
r = reclass_rs.Reclass.from_config(
"./tests/inventory-class-notfound-regexp", "reclass-config.yml"
)
Expand All @@ -24,3 +24,14 @@ def test_ignore_regexp_render_n1():
ValueError, match="Error while rendering n2: Class foo not found"
):
n2 = r.nodeinfo("n2")


def test_ignore_regexp_update_config_render_n2():
r = reclass_rs.Reclass.from_config(
"./tests/inventory-class-notfound-regexp", "reclass-config.yml"
)
r.set_ignore_class_notfound_regexp([".*"])
assert r.config.ignore_class_notfound_regexp == [".*"]

n2 = r.nodeinfo("n2")
assert n2 is not None

0 comments on commit d2d8ba4

Please sign in to comment.