def test_time(self): package_type = 0x01 package = [0x00] * 7 time = datetime.datetime.now() dp = RealtimeDataPoint(package_type, package, time=time) self.assertEqual(dp.time, time) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_reserved(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 8): package[2] = 0x00 | value << 5 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.reserved, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_pi_valid(self): package_type = 0x01 package = [0x00] * 7 for value in [False, True]: package[2] = 0x00 | value << 4 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.pi_valid, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_bar_graph(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 16): package[2] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.bar_graph, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_spO2(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 256): package[4] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.spO2, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_pulse_waveform(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 127): package[1] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.pulse_waveform, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_probe_error(self): package_type = 0x01 package = [0x00] * 7 for value in [False, True]: package[0] = 0x00 | value << 7 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.probe_error, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_low_spO2(self): package_type = 0x01 package = [0x00] * 7 for value in [False, True]: package[0] = 0x00 | value << 5 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.low_spO2, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_signal_strength(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 16): package[0] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.signal_strength, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_spO2_invalid(self): package_type = 0x01 package = [0x00] * 7 for value in [0, 127]: package[4] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.spO2_invalid, bool(value)) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_pulse_rate_invalid(self): package_type = 0x01 package = [0x00] * 7 for value in [0, 255]: package[3] = 0x00 | value dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.pulse_rate_invalid, bool(value)) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_searching_pulse(self): package_type = 0x01 package = [0x00] * 7 for value in [False, True]: package[1] = 0x00 | value << 7 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.searching_pulse, value) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_pi_invalid(self): package_type = 0x01 package = [0x00] * 7 for value in [0, 65535]: package[5] = 0x00 | value & 0x00ff package[6] = 0x00 | (value & 0xff00) >> 8 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.pi_invalid, bool(value)) self.assertEqual(dp.get_package(), package) self.assertEqual(dp.__repr__(), eval(dp.__repr__()).__repr__())
def test_pi(self): package_type = 0x01 package = [0x00] * 7 for value in range(0, 65536): package[5] = 0x00 | value & 0x00ff package[6] = 0x00 | (value & 0xff00) >> 8 dp = RealtimeDataPoint(package_type, package) self.assertEqual(dp.pi, value)
def test_init_package_type(self): package = test_package(7) # right type package_type = 0x01 RealtimeDataPoint(package_type, package) # wrong type package_type = 0x00 self.assertRaisesRegex(ValueError, 'package type', RealtimeDataPoint, package_type, [])
def test_init_package_length(self): package_type = 0x01 # right length package = test_package(7) RealtimeDataPoint(package_type, package) # wrong length package = test_package(6) self.assertRaisesRegex(ValueError, 'package length', RealtimeDataPoint, package_type, package)
def test_get_package(self): package_type = 0x01 package = test_package(7) dp = RealtimeDataPoint(package_type, package) self.assertEqual(package, dp.get_package())