From 09e06301afa3e27feed0c9b3dc1b5133e410e3be Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sun, 24 Sep 2023 16:56:47 +0200 Subject: [PATCH] Add tests --- tests/helpers/test_cache.py | 12 ++++++++++++ .../test_expected_scores_format_change.py | 12 ++++++++---- tests/version_changes/util.py | 9 +++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/version_changes/util.py diff --git a/tests/helpers/test_cache.py b/tests/helpers/test_cache.py index 9f573065..e6c89fe0 100644 --- a/tests/helpers/test_cache.py +++ b/tests/helpers/test_cache.py @@ -94,3 +94,15 @@ def test_cache(): assert os.path.exists(paths.get_cache_path("md5sums", "abc.py")) assert cache.get_cache_file("abc.py") == cache_file assert cache.get_cache_file("abc.cpp") == CacheFile() + + # Test if after changing contest type all cached test results are removed + cache_file.save("abc.cpp") + cache_file.save("abc.py") + + cache.check_if_contest_type_changed("default") + assert cache.get_cache_file("abc.py") == cache_file + assert cache.get_cache_file("abc.cpp") == cache_file + + cache.check_if_contest_type_changed("oi") + assert cache.get_cache_file("abc.py").tests == {} + assert cache.get_cache_file("abc.cpp").tests == {} diff --git a/tests/version_changes/test_expected_scores_format_change.py b/tests/version_changes/test_expected_scores_format_change.py index 9a721807..31d5ee93 100644 --- a/tests/version_changes/test_expected_scores_format_change.py +++ b/tests/version_changes/test_expected_scores_format_change.py @@ -5,13 +5,12 @@ from tests.fixtures import create_package from sinol_make.util import make_version_changes import sinol_make +from tests.version_changes.util import change_version @pytest.mark.parametrize("create_package", [util.get_simple_package_path()], indirect=True) def test_version_change(create_package): - orig_version = sinol_make.__version__ - sinol_make.__version__ = "1.5.9" - + change_version("1.5.9") with open("config.yml", "r") as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader) old_expected_scores = config["sinol_expected_scores"] @@ -28,4 +27,9 @@ def test_version_change(create_package): with open("config.yml", "r") as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader) assert config["sinol_expected_scores"] == old_expected_scores - sinol_make.__version__ = orig_version + + change_version("1.6.0") + make_version_changes() + with open("config.yml", "r") as config_file: + config = yaml.load(config_file, Loader=yaml.FullLoader) + assert config["sinol_expected_scores"] == old_expected_scores diff --git a/tests/version_changes/util.py b/tests/version_changes/util.py new file mode 100644 index 00000000..9cf71bc7 --- /dev/null +++ b/tests/version_changes/util.py @@ -0,0 +1,9 @@ +import yaml + + +def change_version(version): + with open("config.yml", "r") as config_file: + config = yaml.load(config_file, Loader=yaml.FullLoader) + config["sinol_version"] = version + with open("config.yml", "w") as config_file: + yaml.dump(config, config_file)