From 42b4798d8510c3ed1620f4e72e78cc27f660e6af Mon Sep 17 00:00:00 2001 From: mschwoerer <82171591+mschwoer@users.noreply.github.com> Date: Thu, 19 Dec 2024 07:36:42 +0100 Subject: [PATCH 1/2] add more unit tests for config --- ...{test_config_updater.py => test_config.py} | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) rename tests/unit_tests/{test_config_updater.py => test_config.py} (50%) diff --git a/tests/unit_tests/test_config_updater.py b/tests/unit_tests/test_config.py similarity index 50% rename from tests/unit_tests/test_config_updater.py rename to tests/unit_tests/test_config.py index 61696e0aa..868812126 100644 --- a/tests/unit_tests/test_config_updater.py +++ b/tests/unit_tests/test_config.py @@ -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(): + """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], + }, + ], + } From f83dd9b875593cba9c2cffa8bf9417da9ea6e494 Mon Sep 17 00:00:00 2001 From: mschwoerer <82171591+mschwoer@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:55:54 +0100 Subject: [PATCH 2/2] install mono in CI install mono in CI --- .github/workflows/_run_tests.yml | 5 +++++ misc/pip_install.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/_run_tests.yml b/.github/workflows/_run_tests.yml index e5032c140..92436ac9e 100644 --- a/.github/workflows/_run_tests.yml +++ b/.github/workflows/_run_tests.yml @@ -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: | diff --git a/misc/pip_install.sh b/misc/pip_install.sh index bbfd53529..2ca0b8b8f 100644 --- a/misc/pip_install.sh +++ b/misc/pip_install.sh @@ -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=""