Skip to content

Commit

Permalink
Fix changing version breaking config
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 24, 2023
1 parent 13351c2 commit c87f551
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/sinol_make/structs/status_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def from_str(status):
else:
raise ValueError(f"Unknown status: '{status}'")

@staticmethod
def possible_statuses():
return [Status.PENDING, Status.CE, Status.TL, Status.ML, Status.RE, Status.WA, Status.OK]


@dataclass
class ResultChange:
Expand Down
32 changes: 19 additions & 13 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import sinol_make
from sinol_make.contest_types import get_contest_type
from sinol_make.structs.status_structs import Status


def get_commands():
Expand Down Expand Up @@ -87,10 +88,12 @@ def save_config(config):
{
"key": "sinol_expected_scores",
"default_flow_style": None
}
},
"sinol_make_version",
]

config = config.copy()
config["sinol_make_version"] = sinol_make.__version__
with open("config.yml", "w") as config_file:
for field in order:
if isinstance(field, dict): # If the field is a dict, it means that it has a custom property (for example default_flow_style).
Expand Down Expand Up @@ -294,14 +297,13 @@ def get_file_md5(path):


def make_version_changes():
if compare_versions(sinol_make.__version__, "1.5.8") == 1:
# In version 1.5.9 we changed the format of sinol_expected_scores.
# Now all groups have specified points and status.

if find_and_chdir_package():
with open("config.yml", "r") as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)

if find_and_chdir_package():
with open("config.yml", "r") as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)
if "sinol_make_version" not in config:
config["sinol_make_version"] = "1.5.9"
if compare_versions(config["sinol_make_version"], "1.5.10") == -1:
# If the version is less than 1.5.10, we change the format of `sinol_expected_scores` field.
try:
new_expected_scores = {}
expected_scores = config["sinol_expected_scores"]
Expand All @@ -316,11 +318,15 @@ def make_version_changes():
for solution, results in expected_scores.items():
new_expected_scores[solution] = {"expected": {}, "points": results["points"]}
for group, result in results["expected"].items():
new_expected_scores[solution]["expected"][group] = {"status": result}
if result == "OK":
new_expected_scores[solution]["expected"][group]["points"] = scores[group]
if result in Status.possible_statuses():
new_expected_scores[solution]["expected"][group] = {"status": result}
if result == "OK":
new_expected_scores[solution]["expected"][group]["points"] = scores[group]
else:
new_expected_scores[solution]["expected"][group]["points"] = 0
else:
new_expected_scores[solution]["expected"][group]["points"] = 0
# This means that the result is probably valid.
new_expected_scores[solution]["expected"][group] = result
config["sinol_expected_scores"] = new_expected_scores
save_config(config)
except:
Expand Down
11 changes: 10 additions & 1 deletion tests/commands/run/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ def test_simple(create_package, time_tool):
"""
package_path = create_package
create_ins_outs(package_path)

parser = configure_parsers()

with open(os.path.join(os.getcwd(), "config.yml"), "r") as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)
expected_scores = config["sinol_expected_scores"]

args = parser.parse_args(["run", "--time-tool", time_tool])
command = Command()
command.run(args)

with open(os.path.join(os.getcwd(), "config.yml"), "r") as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)
assert config["sinol_expected_scores"] == expected_scores


@pytest.mark.parametrize("create_package", [get_simple_package_path(), get_verify_status_package_path(),
get_checker_package_path(), get_library_package_path(),
Expand Down Expand Up @@ -95,6 +102,8 @@ def test_apply_suggestions(create_package, time_tool):

with open(config_path, "r") as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)
print("xddd")
print(config["sinol_expected_scores"])
assert config["sinol_expected_scores"] == expected_scores


Expand Down

0 comments on commit c87f551

Please sign in to comment.