def test_lifetime_can_be_initialised(self): # Arrange lifetime = 0.1 # Act msg = Message(MessageType.INFO, "hello", lifetime) # Assert time.sleep(lifetime) self.assertTrue(msg.has_expired())
def test_parameters_initalised_correctly(self): # Arrange type = MessageType.WARNING content = "hello there" # Act msg = Message(type, content) # Assert self.assertEqual(msg.type(), type) self.assertEqual(msg.content(), content)
def test_message_has_default_lifetime(self): # Arrange expected_lifetime = 2 # Act msg = Message(MessageType.INFO, "hello") # Assert time.sleep(expected_lifetime / 2) self.assertFalse(msg.has_expired()) time.sleep(expected_lifetime / 2) self.assertTrue(msg.has_expired())
def from_scanner_message(scanner_msg): return Message(MessageType.WARNING, scanner_msg.content())
def puck_recorded_message(): return Message(MessageType.INFO, "Puck barcode recorded")
def camera_not_found_message(): return Message( MessageType.WARNING, "camera can not be found.\nEnter the configuration to select the camera.", lifetime=0)
def puck_scan_completed_message(): return Message(MessageType.INFO, "Scan completed!")
def scan_completed_message(): return Message(MessageType.INFO, "Scan completed")
def scan_timeout_message(): return Message(MessageType.WARNING, "Scan timeout")
def latest_barcode_message(): return Message(MessageType.WARNING, "Puck barcode already in latest record", lifetime=3)