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

add more unit tests for config #414

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .github/workflows/_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
- name: Conda info
shell: bash -l {0}
run: conda info
- name: Install mono
shell: bash -l {0}
run: |
conda install mono

- name: Perform pip installation with all stable dependencies
shell: bash -l {0}
run: |
Expand Down
2 changes: 1 addition & 1 deletion misc/pip_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INSTALL_TYPE=$1 # stable, loose, etc..
ENV_NAME=${2:-alphadia}
PYTHON_VERSION=${3:-3.11}

conda create -n $ENV_NAME python=$PYTHON_VERSION -y
conda create -n $ENV_NAME python=$PYTHON_VERSION mono -y

if [ "$INSTALL_TYPE" = "loose" ]; then
INSTALL_STRING=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,138 @@ def test_get_modifications_table():
target = pd.read_csv(StringIO(target_tsv), sep="\t", index_col=0)

pd.testing.assert_frame_equal(table, target)


generic_default_config = """
simple_value_int: 1
simple_value_float: 2.0
simple_value_str: three
nested_values:
nested_value_1: 1
nested_value_2: 2
simple_list:
- 1
- 2
- 3
nested_list:
- name: nested_list_value_1
key1: value11
key2: value21
key3:
- 311
- 312
- 313
- name: nested_list_value_2
key1: value12
key2: value22
key3:
- 312
- 322
- 323
"""

expected_generic_default_config_dict = {
"simple_value_int": 1,
"simple_value_float": 2.0,
"simple_value_str": "three",
"nested_values": {"nested_value_1": 1, "nested_value_2": 2},
"simple_list": [1, 2, 3],
"nested_list": [
{
"name": "nested_list_value_1",
"key1": "value11",
"key2": "value21",
"key3": [311, 312, 313],
},
{
"name": "nested_list_value_2",
"key1": "value12",
"key2": "value22",
"key3": [312, 322, 323],
},
],
}


def test_config_update_empty_list():
"""Test updating a config with an empty list."""
config_1 = Config("default")
config_1.from_dict(yaml.safe_load(StringIO(generic_default_config)))

# when
config_1.update([])

assert config_1.to_dict() == expected_generic_default_config_dict


def test_config_update_simple_two_files():
"""Test updating a config with simple values from two files."""
config_1 = Config("default")
config_1.from_dict(yaml.safe_load(StringIO(generic_default_config)))

config_2 = Config("first")
config_2.from_dict({"simple_value_int": 2, "simple_value_float": 4.0})

config_3 = Config("second")
config_3.from_dict(
{
"simple_value_float": 5.0, # overwrites first
"simple_value_str": "six", # overwrites default
}
)

# when
config_1.update([config_2, config_3], print_modifications=True)

assert config_1.to_dict() == expected_generic_default_config_dict | {
"simple_value_int": 2,
"simple_value_float": 5.0,
"simple_value_str": "six",
}


def test_config_update_advanced():
mschwoer marked this conversation as resolved.
Show resolved Hide resolved
"""Test updating a config with nested values and lists"""
config_1 = Config("default")
config_1.from_dict(yaml.safe_load(StringIO(generic_default_config)))

config_2 = Config("first")
config_2.from_dict(
{
"nested_values": {"nested_value_2": 42},
"simple_list": [43, 44, 45, 999],
"nested_list": [
{
# "name": ""
"key1": "46",
# "key2": ""
"key3": [47, 48, 49],
},
],
}
)

# when
config_1.update([config_2], print_modifications=True)

assert config_1.to_dict() == expected_generic_default_config_dict | {
"nested_values": {
"nested_value_1": 1, # original value
"nested_value_2": 42,
},
"simple_list": [43, 44, 45], # 4th element is ignored
"nested_list": [
{
"name": "nested_list_value_1", # original value
"key1": "46",
"key2": "value21", # original value
"key3": [47, 48, 49],
},
{ # second list item is not changed
"name": "nested_list_value_2",
"key1": "value12",
"key2": "value22",
"key3": [312, 322, 323],
},
],
}
Loading