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
 def test_init_metadata_contains_status(self):
     with pytest.raises(ValueError):
         TINECameraSource(
             self.dummy_address, self.dummy_property,
             metadata={"status": "bad"})
 def test_init_failure(self):
     device_address = "/CONTEXT/server/other_device"
     property_name = "frame"
     with pytest.raises(RuntimeError):
         TINECameraSource(device_address, property_name)
 def test_init_success(self):
     s = TINECameraSource(self.dummy_address, self.dummy_property)
     assert s.device_address == self.dummy_address
     assert s.property_name == self.dummy_property
     assert s.metadata == {}