Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: add list/dict merging feature to triggers #2793

Merged
merged 24 commits into from
Mar 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions test/programs/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,35 @@ def test_generate_yaml(self):
user_path.cached_path = user_path_backup

self.assertOutput(self.output_tempdir.name)

def test_update_weights(self):
original_weights = {
"scalar_1": 50,
"scalar_2": 25,
"list_1": ["string"],
"dict_1": {"option_a": 50, "option_b": 50},
"dict_2": {"option_f": 50},
"set_1": {"option_c"}
}

# test that we don't allow +merge syntax on scalar variables
with self.assertRaises(BaseException):
Generate.update_weights(original_weights, {"+scalar_1": 0}, "Tested", "")

new_weights = Generate.update_weights(original_weights, {"scalar_2": 0,
"+list_1": ["string_2"],
"+dict_1": {"option_b": 0, "option_c": 50},
"+set_1": {"option_c", "option_d"},
"dict_2": {"option_g": 50},
"+list_2": ["string_3"]},
"Tested", "")

self.assertTrue(new_weights["scalar_1"] == 50 and new_weights["scalar_2"] == 0)
self.assertTrue("list_2" in new_weights
and len(new_weights["list_2"]) == 1
and new_weights["list_2"] == ["string_3"])
self.assertTrue(len(new_weights["list_1"]) == 2 and new_weights["list_1"] == ["string", "string_2"])
self.assertTrue(new_weights["dict_1"]["option_b"] == 0 and new_weights["dict_1"]["option_a"] == 50)
self.assertTrue("option_c" in new_weights["dict_1"] and new_weights["dict_1"]["option_c"] == 50)
self.assertTrue("option_f" not in new_weights["dict_2"] and new_weights["dict_2"]["option_g"] == 50)
self.assertTrue(len(new_weights["set_1"]) == 2 and "option_d" in new_weights["set_1"])
black-sliver marked this conversation as resolved.
Show resolved Hide resolved
Loading