def test_csv_roundtrip(self):
        aesthetic_settings = AestheticSettings()
        paths = AestheticSettings.get_csv_data_paths()
        for i, path in enumerate(paths):
            aesthetic, setting = path
            aesthetic_settings.__dict__[aesthetic].__dict__[setting] = i
        aesthetic_settings.mission_aesthetic.hazard_spread_probability = {
            Tiles.water: 1,
            Tiles.fire: 2
        }
        aesthetic_settings.mission_graph_aesthetic.branch_probability = [
            0, 1, 2, 3
        ]
        csv_data = aesthetic_settings.to_csv_data()
        expected_csv_data = [
            "0", "1", "2", "3", "4", "5", "6", "[1, 2]", "8", "9", "10",
            "[0, 1, 2, 3]", "12", "13", "14", "15", "16", "17", "18", "19"
        ]

        self.assertEqual(expected_csv_data, csv_data)

        aesthetic_settings2 = AestheticSettings()
        aesthetic_settings2.from_csv_data(csv_data)

        expected_values = [
            0.0, 1.0, 2, 3, 4, 5.0, 6.0, {
                Tiles.water: 1.0,
                Tiles.fire: 2.0
            }, 8, 9, 10.0, [0.0, 1.0, 2.0, 3.0], 12.0, 13.0, 14.0, 15, 16, 17,
            18, 19.0
        ]
        for path, expected_value in zip(paths, expected_values):
            aesthetic, setting = path
            value = aesthetic_settings2.__dict__[aesthetic].__dict__[setting]
            self.assertEqual(value, expected_value)
Beispiel #2
0
 def level_aesthetic(self, i):
     data = self.file_data.splitlines()[i].split(
         Ratings.CSV_SEPARATOR)[Ratings.
                                SETTINGS_INDEX:Ratings.SETTINGS_INDEX +
                                len(AestheticSettings.get_csv_data_paths())]
     aesthetic = AestheticSettings()
     aesthetic.from_csv_data(data)
     return aesthetic