First upload, 18 controller version
This commit is contained in:
60
tests/test_xml_mapping.py
Normal file
60
tests/test_xml_mapping.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
from app.config.xml_mapping import config_to_xml_string, load_config, load_config_from_string, validate_config
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SAMPLE_MAPPING = ROOT / "sample_data" / "infinity_mirror_mapping_clean.xml"
|
||||
|
||||
|
||||
class XmlMappingTests(unittest.TestCase):
|
||||
def test_sample_mapping_loads_and_validates(self) -> None:
|
||||
config = load_config(SAMPLE_MAPPING)
|
||||
self.assertEqual(config.logical_display.rows, 3)
|
||||
self.assertEqual(config.logical_display.cols, 6)
|
||||
self.assertEqual(len(config.tiles), 18)
|
||||
self.assertTrue(validate_config(config).is_valid)
|
||||
|
||||
def test_round_trip_preserves_tile_count_and_ids(self) -> None:
|
||||
config = load_config(SAMPLE_MAPPING)
|
||||
xml_text = config_to_xml_string(config)
|
||||
restored = load_config_from_string(xml_text)
|
||||
self.assertEqual(len(restored.tiles), len(config.tiles))
|
||||
self.assertEqual([tile.tile_id for tile in restored.sorted_tiles()], [tile.tile_id for tile in config.sorted_tiles()])
|
||||
|
||||
def test_round_trip_preserves_optional_controller_metadata(self) -> None:
|
||||
config = load_config(SAMPLE_MAPPING)
|
||||
tile = config.tile_lookup()["r1c1"]
|
||||
tile.controller_host = "wled-r1c1.local"
|
||||
tile.controller_name = "Front Left"
|
||||
tile.controller_mac = "AA:BB:CC:DD:EE:FF"
|
||||
|
||||
restored = load_config_from_string(config_to_xml_string(config))
|
||||
restored_tile = restored.tile_lookup()["r1c1"]
|
||||
|
||||
self.assertEqual(restored_tile.controller_ip, tile.controller_ip)
|
||||
self.assertEqual(restored_tile.controller_host, "wled-r1c1.local")
|
||||
self.assertEqual(restored_tile.controller_name, "Front Left")
|
||||
self.assertEqual(restored_tile.controller_mac, "AA:BB:CC:DD:EE:FF")
|
||||
|
||||
def test_sample_mapping_first_row_is_not_left_right_mirrored(self) -> None:
|
||||
config = load_config(SAMPLE_MAPPING)
|
||||
first_row = [tile.screen_name for tile in config.sorted_tiles() if tile.row == 1]
|
||||
self.assertEqual(
|
||||
first_row,
|
||||
[
|
||||
"Lumiverse 1",
|
||||
"Lumiverse 4",
|
||||
"Lumiverse 7",
|
||||
"Lumiverse 10",
|
||||
"Lumiverse 13",
|
||||
"Lumiverse 16",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user