Example #1
0
 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_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))
Example #3
0
    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_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