Example #1
0
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]
Example #2
0
 def test_hexify_float(self):
     with self.assertRaises(TypeError):
         hexify(33.88)
Example #3
0
 def test_hexify_negative(self):
     with self.assertRaisesRegex(
             ValueError, 'Invalid number to hexify - must be positive'):
         hexify(-700)
Example #4
0
 def test_hexify_256(self):
     self.assertEqual(hexify(256), '0100')
Example #5
0
 def test_hexify_12(self):
     self.assertEqual(hexify(12), '0C')
Example #6
0
 def test_hexify_zero(self):
     self.assertEqual(hexify(0), '00')