-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/#125] Enhance configuration management by using toml configu…
…ration file (#296) Co-authored-by: karmacoma <karma@coma.lol>
- Loading branch information
1 parent
b5bef1f
commit 4037b2f
Showing
5 changed files
with
175 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This is an example file for configuring the Halmos settings. | ||
# For configuration values, refer to the options listed under the 'halmos --help' command. | ||
# You may freely use sections to categorize the settings as needed. | ||
|
||
[settings] | ||
depth = 4 | ||
|
||
[compile-settings] | ||
array-lengths = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import argparse | ||
from unittest.mock import mock_open, patch | ||
|
||
import pytest | ||
|
||
from halmos.parser import load_config_file, parse_config | ||
|
||
|
||
@pytest.fixture | ||
def mock_config(): | ||
return { | ||
"settings": { | ||
"depth": 4, | ||
"array-lengths": 2, | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def mock_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--depth", type=int) | ||
parser.add_argument("--array-lengths") | ||
return parser | ||
|
||
|
||
@pytest.fixture | ||
def mock_args(): | ||
args = argparse.Namespace() | ||
args.root = "/fake/path" | ||
args.config = "halmos.toml" | ||
args.depth = None | ||
args.array_lengths = None | ||
return args | ||
|
||
|
||
def test_load_config_file_not_found(monkeypatch): | ||
monkeypatch.setattr("os.path.exists", lambda x: False) | ||
assert load_config_file("not_exist.toml") is None | ||
|
||
|
||
def test_parse_config_success(mock_config, mock_parser, mock_args): | ||
updated_args = parse_config(mock_config, mock_parser, mock_args, []) | ||
assert updated_args.depth == 4 | ||
assert updated_args.array_lengths == 2 | ||
|
||
|
||
def test_parse_config_invalid_key(mock_parser, mock_args): | ||
invalid_key_config = { | ||
"settings": { | ||
"invalid_key": "invalid", | ||
} | ||
} | ||
updated_args = parse_config(invalid_key_config, mock_parser, mock_args, []) | ||
assert not hasattr(updated_args, "invalid_key") | ||
|
||
|
||
def test_parse_config_invalid_type(mock_parser, mock_args): | ||
invalid_type_config = { | ||
"settings": { | ||
"depth": "invalid", | ||
"array-lengths": 2, | ||
} | ||
} | ||
updated_args = parse_config(invalid_type_config, mock_parser, mock_args, []) | ||
assert updated_args.depth is None | ||
assert updated_args.array_lengths == 2 | ||
|
||
|
||
def test_parse_config_skip_in_commands(mock_config, mock_parser, mock_args): | ||
mock_args.depth = 5 | ||
updated_args = parse_config(mock_config, mock_parser, mock_args, ["--depth", "5"]) | ||
|
||
assert updated_args.depth == 5 | ||
assert updated_args.array_lengths == 2 |