def test_read_success(self, tine_data): img, reply = tine_data s = TINECameraSource(self.dummy_address, self.dummy_property, metadata={"device": self.dummy_address}) data = s.read() timestamp = datetime.datetime.fromtimestamp( reply["timestamp"], timezone("Europe/Berlin")) assert data.timestamp == timestamp assert data.failure is None np.testing.assert_array_equal(data.value[self.dummy_property], img) assert data.metadata is not s.metadata assert data.metadata["device"] == self.dummy_address
def test_read_corrupted_data(self, tine_data): img, reply = tine_data reply["data"]["imageBytes"] = b"bad" s = TINECameraSource(self.dummy_address, self.dummy_property, metadata={"device": self.dummy_address}) data = s.read() timestamp = datetime.datetime.fromtimestamp( reply["timestamp"], timezone("Europe/Berlin")) assert data.timestamp == timestamp assert isinstance(data.failure, ValueError) assert data.value is None assert data.metadata is not s.metadata assert data.metadata["device"] == self.dummy_address
def test_read_wrong_status(self, tine_mock): maxdelta = datetime.timedelta(seconds=5) s = TINECameraSource(self.dummy_address, self.dummy_property, metadata={"device": self.dummy_address}) tine_mock.get.side_effect = None tine_mock.get.return_value = dict(status=1) data = s.read() now = datetime.datetime.now(timezone("Europe/Berlin")) assert data.timestamp - now < maxdelta assert data.failure is None assert data.value is None assert data.metadata is not s.metadata assert data.metadata["device"] == self.dummy_address
def test_read_error(self, tine_mock): maxdelta = datetime.timedelta(seconds=5) s = TINECameraSource(self.dummy_address, self.dummy_property, metadata={"device": self.dummy_address}) ex = RuntimeError("Some error") tine_mock.get.side_effect = ex data = s.read() now = datetime.datetime.now(timezone("Europe/Berlin")) assert data.timestamp - now < maxdelta assert data.failure is ex assert data.value is None assert data.metadata is not s.metadata assert data.metadata["device"] == self.dummy_address