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