guanghu-ice-heart/server-tools/heartbeat-office-building/test_office_building.py

66 lines
2.9 KiB
Python

#!/usr/bin/env python3
import importlib.util
import json
import time
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
COMPUTER = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/smart-computer/office_computer.py"
LOADER = ROOT / "skills/shared/hololake-development-brain/scripts/load_hololake_office.py"
def module(path, name):
spec = importlib.util.spec_from_file_location(name, path)
value = importlib.util.module_from_spec(spec)
spec.loader.exec_module(value)
return value
C = module(COMPUTER, "office_computer_test")
L = module(LOADER, "hololake_loader_test")
class Tests(unittest.TestCase):
def test_office_board_has_exactly_two_registered_offices(self):
board = C.load(C.BOARD)
self.assertEqual([x["office_id"] for x in board["offices"]], ["HB-OFFICE-VIDEO-0001", "HB-OFFICE-HOLOLAKE-0001"])
self.assertEqual(board["office_count"], 2)
def test_old_building_is_moved_and_new_building_is_current(self):
building = C.load(C.BUILDING_MAP)
self.assertEqual(building["legacy_building"]["state"], "MOVED_HISTORY_ONLY")
self.assertEqual(building["current_building"]["id"], "HB-BUILDING-0001")
self.assertFalse(building["current_building"]["projection_may_override_canon"])
def test_time_is_live_and_monotonic(self):
first = C.clock(); time.sleep(0.01); second = C.clock()
self.assertGreater(second["guanghu_elapsed_milliseconds"], first["guanghu_elapsed_milliseconds"])
self.assertEqual(second["time_control_channel"], "CH-GLW-TIME-0001")
def test_status_is_read_only(self):
tracked = [C.BOARD, C.BUILDING_MAP, C.GENERATION, C.EVOLUTION, C.CURRENT, C.BRAIN]
before = {str(path): C.sha(path) for path in tracked}
value = C.status()
after = {str(path): C.sha(path) for path in tracked}
self.assertEqual(before, after)
self.assertTrue(value["query_is_read_only"])
def test_current_evolution_and_old_sequence_boundary(self):
value = C.timeline()
self.assertEqual(value["current"]["node_id"], "HLP-STAGE1-NATIVE-REGISTRY-001")
current = C.load(C.CURRENT)
self.assertIsNone(current["current_product_module"])
self.assertEqual(current["current_generation_module_numbering"], "HLP-NATIVE-MOD-001_TO_018_REDERIVED")
def test_brain_loader_returns_current_generation(self):
value = L.load("恢复HoloLake开发线")
self.assertEqual(value["state"], "HOLOLAKE_DEVELOPMENT_BRAIN_LOADED")
self.assertEqual(value["generation"]["id"], "HLP-GEN-LANGUAGE-WORLD-NATIVE-0001")
self.assertFalse(value["legacy_may_override_current"])
self.assertEqual(value["multipath_console"]["console_id"], "HB-MPC-0001")
self.assertEqual(value["multipath_console"]["total_hosts"], 4)
if __name__ == "__main__":
unittest.main()