def test_to_bytes_out_of_range(self): """ Test to_bytes with out of range values. """ temp = EepromSignedTemp((0, 0)) try: temp.encode(8) self.fail("Expected ValueError.") except ValueError: pass try: temp.encode(45) self.fail("Expected ValueError.") except ValueError: pass try: temp.encode(-8) self.fail("Expected ValueError.") except ValueError: pass try: temp.encode(-89) self.fail("Expected ValueError.") except ValueError: pass
def test_to_bytes(self): """ Test to_bytes. """ temp = EepromSignedTemp((0, 0)) self.assertEquals("\xff", temp.encode(0.0)) self.assertEquals("\x02", temp.encode(1.0)) self.assertEquals("\x82", temp.encode(-1.0)) self.assertEquals("\x0f", temp.encode(7.5)) self.assertEquals("\x8f", temp.encode(-7.5))
def test_from_bytes(self): """ Test from_bytes. """ temp = EepromSignedTemp((0, 0)) self.assertEquals(0.0, temp.decode("\xff")) self.assertEquals(1.0, temp.decode("\x02")) self.assertEquals(-1.0, temp.decode("\x82")) self.assertEquals(7.5, temp.decode("\x0f")) self.assertEquals(-7.5, temp.decode("\x8f"))