def test_encode_int_field(self): """ Test for Field.int.encode """ self.assertEquals('\x00\x00', Field.int("test").encode(0)) self.assertEquals('\x00\x01', Field.int("test").encode(1)) self.assertEquals('\x01\x11', Field.int("test").encode(1*256 + 17)) self.assertEquals('\xFF\xFF', Field.int("test").encode(255*256 + 255)) try: Field.int("test").encode(-1) self.assertTrue(False) except ValueError: pass try: Field.int("test").encode(102400) self.assertTrue(False) except ValueError: pass
def test_decode_int_field(self): """ Test for Field.int.decode """ self.assertEquals(0, Field.int("test").decode('\x00\x00')) self.assertEquals(1, Field.int("test").decode('\x00\x01')) self.assertEquals(1*256 + 17, Field.int("test").decode('\x01\x11')) self.assertEquals(255*256 + 255, Field.int("test").decode('\xFF\xFF')) try: Field.int("test").decode("123") self.assertTrue(False) except ValueError: pass