Esempio n. 1
0
    def test_process_exception_happy(self, bacnet_obj_factory):
        try:
            from BAC0.core.io.IOExceptions import UnknownObjectError  # type: ignore
        except ImportError as import_exc:
            raise NotImplementedError from import_exc

        verifier = BACnetVerifier(override_threshold=Priority.MANUAL_OPERATOR)
        bacnet_obj = bacnet_obj_factory(**{"85": asyncio.TimeoutError()})

        verified_obj = verifier.process_exception(obj=bacnet_obj,
                                                  exc=bacnet_obj.present_value)
        assert verified_obj.present_value == "null"
        assert verified_obj.status_flags.flags == 0b0100
        assert verified_obj.reliability == "timeout"
        assert verified_obj.unreachable_in_row == 1
        assert verified_obj.existing is True

        verified_obj.set_property(value=UnknownObjectError(),
                                  prop=ObjProperty.PRESENT_VALUE)
        verified_obj_2 = verifier.process_exception(
            obj=verified_obj, exc=verified_obj.present_value)
        assert verified_obj_2.present_value == "null"
        assert verified_obj_2.status_flags.flags == 0b0100
        assert verified_obj_2.reliability == Reliability.NO_SENSOR
        assert verified_obj_2.unreachable_in_row == 2
        assert verified_obj_2.existing is False

        verified_obj_2.set_property(value=TypeError(),
                                    prop=ObjProperty.PRESENT_VALUE)
        verified_obj_3 = verifier.process_exception(
            obj=verified_obj_2, exc=verified_obj_2.present_value)
        assert verified_obj_3.present_value == "null"
        assert verified_obj_3.status_flags.flags == 0b0100
        assert verified_obj_3.reliability == "decode-error"
        assert verified_obj_3.unreachable_in_row == 3

        verified_obj_3.set_property(value=AttributeError(),
                                    prop=ObjProperty.PRESENT_VALUE)
        verified_obj_4 = verifier.process_exception(
            obj=verified_obj_3, exc=verified_obj_3.present_value)
        assert verified_obj_4.present_value == "null"
        assert verified_obj_4.status_flags.flags == 0b0100
        assert verified_obj_4.reliability == "AttributeError"
        assert verified_obj_4.unreachable_in_row == 4

        assert (id(bacnet_obj) == id(verified_obj) == id(verified_obj_2) ==
                id(verified_obj_3) == id(verified_obj_4))
Esempio n. 2
0
 def test_process_exception_bad_exception(self, bacnet_obj_factory):
     verifier = BACnetVerifier(override_threshold=Priority.MANUAL_OPERATOR)
     bacnet_obj = bacnet_obj_factory(**{"85": "not_exception"})
     with pytest.raises(ValueError):
         verifier.process_exception(obj=bacnet_obj,
                                    exc=bacnet_obj.present_value)