def test_invalid(self): with self.assertRaises(TypeError): NodeID(123456) with self.assertRaises(TypeError): NodeID(u'zlew') with self.assertRaises(ValueError): NodeID(b'\x11'*(NodeID.WIDTH-1)) with self.assertRaises(ValueError): NodeID(b'\x11'*(NodeID.WIDTH+1)) with self.assertRaises(TypeError): NodeID.from_hex(123456) with self.assertRaises(ValueError): NodeID.from_hex('11'*(NodeID.WIDTH-1)) with self.assertRaises(ValueError): NodeID.from_hex('11'*(NodeID.WIDTH+1))
def test_from_hex(self): obj = NodeID.from_hex('1112'*(NodeID.WIDTH//2)) self.assertEqual(b'\x11\x12'*(NodeID.WIDTH//2), obj.bytes)
def test_restricted(self): with self.assertRaises(ValueError): NodeID(b'\x00'*NodeID.WIDTH) with self.assertRaises(ValueError): NodeID.from_hex('00'*NodeID.WIDTH)