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