import dataclasses import pytest from exporter.models import ( DeviceMetricsSnapshot, INT32_MAX, TransceiverChannelRecord, TransceiverRecord, is_invalid_value, ) def test_transceiver_record_is_frozen(): record = TransceiverRecord( device="dev1", component_name="comp1", logical_port="1/0/1", present="PRESENT", oper_status="ACTIVE", temperature_c=40.0, supply_voltage_v=3.3, vendor="H3C", serial="SN1", part_number="PN", hardware_rev="1.0", ) with pytest.raises(dataclasses.FrozenInstanceError): record.device = "dev2" def test_transceiver_channel_record_is_frozen(): channel = TransceiverChannelRecord( device="dev1", component_name="comp1", logical_port="1/0/1", channel_index=0, logical_channel="1/0/1:1", rx_power_dbm=-3.0, tx_power_dbm=-1.0, bias_current_ma=10.0, laser_temperature_c=25.0, ) with pytest.raises(dataclasses.FrozenInstanceError): channel.channel_index = 1 def test_snapshot_is_frozen(): tx = TransceiverRecord(device="d", component_name="c", logical_port="p") snap = DeviceMetricsSnapshot(device="d", collected_at=0.0, transceivers=(tx,), channels=()) with pytest.raises(dataclasses.FrozenInstanceError): snap.device = "other" @pytest.mark.parametrize( "value, expected", [ (float(INT32_MAX), True), (INT32_MAX, True), (INT32_MAX - 1, False), (-INT32_MAX, False), (None, False), ], ) def test_is_invalid_value_exact_int32_max(value, expected): assert is_invalid_value(value) is expected