def test_uuid_shorthex(self): "Test Uuid class support for short hex values" tag = uuid.Uuid.tags.get('Account') uuid1 = uuid.Uuid(73786976294838235846, tag) self.assertEquals(uuid1.shorthex, '400000000000072c6') uuid2 = uuid.Uuid(5, tag) self.assertEquals(uuid2.shorthex, '5')
def test_uuid_high_low(self): "Test Uuid class support for high/low number" tag = uuid.Uuid.tags.get('Account') uuid1 = uuid.Uuid(73786976294838235846, tag) self.assertEquals(uuid1.low, 29382) self.assertEquals(uuid1.high, 4) uuid2 = uuid.Uuid(5, tag) self.assertEquals(uuid2.low, 5) self.assertEquals(uuid2.high, 0)
def test_bad_base_raises(self): "Test that Uuid class raises TypeError when given a bad 'base' value" tag = uuid.Uuid.tags.get('Account') uuid1 = uuid.Uuid(73786976294838235846, tag) self.assertRaises(TypeError, lambda: uuid1.to_slug(base=90)) self.assertRaises(TypeError, lambda: uuid1.to_slug(base=1)) self.assertRaises(TypeError, lambda: uuid1.to_slug(base=-1)) self.assertRaises(TypeError, lambda: uuid1.to_slug(chars='abc', base=4))
def test_slug(self): "Test that Uuid can be converted to/from slugs" tag = uuid.Uuid.tags.get('Account') uuid1 = uuid.Uuid(73786976294838235846, tag) slug = 'a-lvgb2h48s4kweqbl' self.assertEquals(uuid1.to_slug(), slug) self.assertEquals( uuid1.to_slug(base=16)[2:], uuid1.to_hex().lstrip('0')) uuid2 = uuid.Uuid.from_slug(slug) self.assertEquals(uuid1, uuid2)
def test_hex(self): "Test that Uuid can be converted to/from hex" tag = uuid.Uuid.tags.get('Account') uuid1 = uuid.Uuid(73786976294838235846, tag) hex_str = '00000000000400000000000072c6acc1' self.assertEquals(uuid1.to_hex(), hex_str) self.assertEquals(uuid1.shorthex, hex_str.lstrip('0')[:-4]) self.assertEquals(uuid1.to_hex(pad=0)[:-4], uuid1.shorthex) uuid2 = uuid.Uuid.from_hex(hex_str) self.assertEquals(uuid1, uuid2) self.assertRaises(TypeError, lambda: uuid.Uuid.from_hex(10)) self.assertRaises(ValueError, lambda: uuid.Uuid.from_hex('aa0000'))
def test_int(self): "Test that Uuid can be converted to/from integer" tag = uuid.Uuid.tags.get('Account') number = 73786976294838235846 low = 29382 high = 4 uuid1 = uuid.Uuid(number, tag) uuid2 = uuid.Uuid.from_int(number, 'Account') self.assertEqual(uuid1, uuid2) self.assertEqual(uuid2.number, number) self.assertEqual(uuid2.high, high) self.assertEqual(uuid2.low, low) uuid3 = uuid.Uuid.from_int((high, low), 'Account') self.assertEquals(uuid1, uuid3) self.assertRaises(TypeError, lambda: uuid.Uuid.from_int('foo', 'Account')) self.assertRaises(TypeError, lambda: uuid.Uuid.from_int(-100, 'Account')) self.assertRaises(ValueError, lambda: uuid.Uuid.from_int(1, 'invalid-type'))