def get_random_hex(length): """ Return random hex string of a given length """ if length <= 0: return '' return hexify(random.randint(pow(2, length*2), pow(2, length*4)))[0:length]
def test_hexify_float(self): with self.assertRaises(TypeError): hexify(33.88)
def test_hexify_negative(self): with self.assertRaisesRegex( ValueError, 'Invalid number to hexify - must be positive'): hexify(-700)
def test_hexify_256(self): self.assertEqual(hexify(256), '0100')
def test_hexify_12(self): self.assertEqual(hexify(12), '0C')
def test_hexify_zero(self): self.assertEqual(hexify(0), '00')