Example #1
0
class UnknownDUIDTestCase(unittest.TestCase):
    def setUp(self):
        self.duid_object = UnknownDUID(duid_type=65535,
                                       duid_data=b'SomeRandomDUIDData')
        self.duid_bytes = bytes.fromhex(
            'ffff536f6d6552616e646f6d4455494444617461')

    def test_hash(self):
        duid_hash = hash(self.duid_object)
        self.assertIsInstance(duid_hash, int)

    def test_parse(self):
        with self.assertRaisesRegex(ValueError, 'length'):
            DUID.parse(self.duid_bytes)

        length = len(self.duid_bytes)
        parsed_length, parsed_object = DUID.parse(self.duid_bytes,
                                                  length=length)
        self.assertEqual(parsed_length, length)
        self.assertEqual(parsed_object, self.duid_object)

    def test_parse_with_larger_buffer(self):
        offset = 50
        buffer = bytes(50 * [0]) + self.duid_bytes + bytes(50 * [0])
        length = len(self.duid_bytes)
        parsed_length, parsed_object = DUID.parse(buffer,
                                                  offset=offset,
                                                  length=length)
        self.assertEqual(parsed_length, length)
        self.assertEqual(parsed_object, self.duid_object)

    def test_save(self):
        saved_bytes = self.duid_object.save()
        self.assertEqual(saved_bytes, self.duid_bytes)
Example #2
0
class UnknownDUIDTestCase(unittest.TestCase):
    def setUp(self):
        self.duid_object = UnknownDUID(duid_type=65535, duid_data=b'SomeRandomDUIDData')
        self.duid_bytes = bytes.fromhex('ffff536f6d6552616e646f6d4455494444617461')

    def test_hash(self):
        duid_hash = hash(self.duid_object)
        self.assertIsInstance(duid_hash, int)

    def test_parse(self):
        with self.assertRaisesRegex(ValueError, 'length'):
            DUID.parse(self.duid_bytes)

        length = len(self.duid_bytes)
        parsed_length, parsed_object = DUID.parse(self.duid_bytes, length=length)
        self.assertEqual(parsed_length, length)
        self.assertEqual(parsed_object, self.duid_object)

    def test_parse_with_larger_buffer(self):
        offset = 50
        buffer = bytes(50 * [0]) + self.duid_bytes + bytes(50 * [0])
        length = len(self.duid_bytes)
        parsed_length, parsed_object = DUID.parse(buffer, offset=offset, length=length)
        self.assertEqual(parsed_length, length)
        self.assertEqual(parsed_object, self.duid_object)

    def test_save(self):
        saved_bytes = self.duid_object.save()
        self.assertEqual(saved_bytes, self.duid_bytes)
Example #3
0
 def setUp(self):
     self.duid_object = UnknownDUID(duid_type=65535,
                                    duid_data=b'SomeRandomDUIDData')
     self.duid_bytes = bytes.fromhex(
         'ffff536f6d6552616e646f6d4455494444617461')
Example #4
0
 def setUp(self):
     self.duid_object = UnknownDUID(duid_type=65535, duid_data=b'SomeRandomDUIDData')
     self.duid_bytes = bytes.fromhex('ffff536f6d6552616e646f6d4455494444617461')