TestVersionUpgrade44To45.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import configparser
  2. import VersionUpgrade44to45
  3. import pytest
  4. before_update = """[general]
  5. version = 4
  6. name = Creality CR-10S_settings
  7. definition = creality_cr10s
  8. [metadata]
  9. type = definition_changes
  10. setting_version = 11
  11. [values]
  12. %s
  13. """
  14. before_after_list = [
  15. ("machine_head_with_fans_polygon = [[-99, 99], [-99, -44], [45, 99], [45, -44]]", "[[-99, 99], [-99, -44], [45, 99], [45, -44]]"),
  16. ("", None),
  17. ("machine_head_polygon = [[-98, 99], [-99, -44], [45, 99], [45, -44]]", "[[-98, 99], [-99, -44], [45, 99], [45, -44]]"),
  18. ("machine_head_polygon = [[-87, 99], [-99, -44], [45, 99], [45, -44]]\nmachine_head_with_fans_polygon = [[-99, 99], [-99, -44], [45, 99], [45, -44]]", "[[-99, 99], [-99, -44], [45, 99], [45, -44]]"),
  19. ]
  20. class TestVersionUpgrade44to45:
  21. @pytest.mark.parametrize("after_string, after_value", before_after_list)
  22. def test_upgrade(self, after_string, after_value):
  23. upgrader = VersionUpgrade44to45.VersionUpgrade44to45()
  24. file_name, new_data = upgrader.upgradeInstanceContainer(before_update % after_string, "whatever")
  25. parser = configparser.ConfigParser(interpolation=None)
  26. parser.read_string(new_data[0])
  27. if after_value is None:
  28. assert "machine_head_with_fans_polygon" not in parser["values"]
  29. else:
  30. assert parser["values"]["machine_head_with_fans_polygon"] == after_value
  31. assert "machine_head_polygon" not in parser["values"]