mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-03-09 08:06:17 +00:00
fix: prevent exception when load prediction data is missing (#925)
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Validate solution prediction data before processing. If required prediction data is missing, the prediction is skipped instead of raising an exception. Introduce a new configuration file saving policy to improve loading robustness: - Exclude computed fields - Exclude fields set to their default values - Exclude fields with value None - Use field aliases - Recursively remove empty dictionaries and lists - Ensure general.version is always present and correctly set When loading older configuration files, computed fields are now stripped before migration. This further improves backward compatibility and loading robustness. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
@@ -22,6 +22,10 @@ MIGRATION_PAIRS = [
|
||||
DIR_TESTDATA / "eos_config_andreas_0_1_0.json",
|
||||
DIR_TESTDATA / "eos_config_andreas_now.json",
|
||||
),
|
||||
(
|
||||
DIR_TESTDATA / "eos_config_unstripped.json",
|
||||
DIR_TESTDATA / "eos_config_stripped.json",
|
||||
),
|
||||
# Add more pairs here:
|
||||
# (DIR_TESTDATA / "old_config_X.json", DIR_TESTDATA / "expected_config_X.json"),
|
||||
]
|
||||
@@ -124,16 +128,18 @@ class TestConfigMigration:
|
||||
new_model = SettingsEOSDefaults(**migrated_data)
|
||||
assert isinstance(new_model, SettingsEOSDefaults)
|
||||
|
||||
def test_migrate_config_file_already_current(self, tmp_path: Path):
|
||||
def test_migrate_config_file_already_current(self, tmp_config_file: Path):
|
||||
"""Test that a current config file returns True immediately."""
|
||||
config_path = tmp_path / "EOS_current.json"
|
||||
default = SettingsEOSDefaults()
|
||||
with config_path.open("w", encoding="utf-8") as f:
|
||||
f.write(default.model_dump_json(indent=4))
|
||||
backup_file = tmp_config_file.with_suffix(".bak")
|
||||
|
||||
backup_file = config_path.with_suffix(".bak")
|
||||
# Run migration
|
||||
result = configmigrate.migrate_config_file(tmp_config_file, backup_file)
|
||||
assert result is True, "Migration should succeed even from invalid version."
|
||||
|
||||
result = configmigrate.migrate_config_file(config_path, backup_file)
|
||||
backup_file.unlink()
|
||||
assert not backup_file.exists()
|
||||
|
||||
result = configmigrate.migrate_config_file(tmp_config_file, backup_file)
|
||||
assert result is True
|
||||
assert not backup_file.exists(), "No backup should be made if config is already current."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user