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

Allow double-adding exact same config option #2397

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions manticore/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def add(self, name: str, default=None, description: str = None):

"""
if name in self._vars:
# Be kind when double-adding the same exact config
existing = self._vars[name]
if default == existing.default and description == existing.description:
return
raise ConfigError(f"{self.name}.{name} already defined.")

if name == "name":
Expand Down
1 change: 1 addition & 0 deletions manticore/wasm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..utils import config

consts = config.get_group("cli")
consts.add("profile", default=False, description="Enable worker profiling mode")
consts.add("target_func", default="main", description="WASM Function to execute")


Expand Down
7 changes: 6 additions & 1 deletion tests/other/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ def test_default_vars(self):
self.assertFalse(g._vars["val1"].was_set)
self.assertTrue(g._vars["val2"].was_set)

def test_double_add(self):
def test_double_add_different(self):
g = config.get_group("test1")
g.add("val1", default="foo")
with self.assertRaises(config.ConfigError):
g.add("val1")

def test_double_add_exact_duplicate(self):
g = config.get_group("test2")
g.add("val1", default="foo", description="Some description")
g.add("val1", default="foo", description="Some description")

def test_update(self):
g = config.get_group("update")
g.add("val", default="default", description="description")
Expand Down
1 change: 0 additions & 1 deletion tests/wasm/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def test_implicit_call(self):
self.assertEqual(sorted(results), [70])

def test_wasm_main(self):
config.get_group("cli").add("profile", False)
m = wasm_main(
namedtuple("Args", ["argv", "workspace", "policy"])([collatz_file], "mcore_tmp", "ALL"),
None,
Expand Down