|
|
|
@ -19,6 +19,8 @@ class TestBytes(TestCase):
|
|
|
|
|
test_list_of_ints = []
|
|
|
|
|
test_list_of_str = []
|
|
|
|
|
for i in range(0, 100):
|
|
|
|
|
# Generate 100 random test cases, each with max_value between
|
|
|
|
|
# 9 and 9,999,999,999,999,999,999,999,999 (25 9's)
|
|
|
|
|
max_value = int("9" * randint(1, 25))
|
|
|
|
|
test_value = randint(1, max_value)
|
|
|
|
|
bitesize = ceil(test_value.bit_length() / 8)
|
|
|
|
@ -74,7 +76,8 @@ class TestBytes(TestCase):
|
|
|
|
|
# print(f"\t\t{testcase}")
|
|
|
|
|
try:
|
|
|
|
|
self.assertIsInstance(eval(test), eval(compare),
|
|
|
|
|
f"{test} is instance of {compare}")
|
|
|
|
|
"{test} is instance of {compare}"
|
|
|
|
|
)
|
|
|
|
|
except:
|
|
|
|
|
import pdb
|
|
|
|
|
pdb.set_trace()
|
|
|
|
@ -95,13 +98,38 @@ class TestBytes(TestCase):
|
|
|
|
|
"""
|
|
|
|
|
Test conversion to hex string
|
|
|
|
|
"""
|
|
|
|
|
with self.subTest("Test hex() function"):
|
|
|
|
|
with self.subTest("Test Bytes.hex() using random values"):
|
|
|
|
|
for testcase in self.testcases["bytes"]:
|
|
|
|
|
self.assertEqual(Bytes(testcase).hex(), testcase.hex(),
|
|
|
|
|
f"Bytes({testcase}).hex() == {testcase}.hex()"
|
|
|
|
|
)
|
|
|
|
|
with self.subTest("Test hex() function with known values"):
|
|
|
|
|
self.assertEqual(Bytes(1234).hex(), "04d2",
|
|
|
|
|
f"Bytes(1234).hex() == '04d2'")
|
|
|
|
|
self.assertEqual(Bytes(1234).hex(":"), "04:d2",
|
|
|
|
|
f"Bytes(1234).hex(':') == '04:d2'")
|
|
|
|
|
self.assertEqual(Bytes(1234).hex(":", 1), "04:d2",
|
|
|
|
|
f"Bytes(1234).hex(':', 1) == '04:d2'")
|
|
|
|
|
with self.subTest("Advanced hex() test"):
|
|
|
|
|
testcase = b'UUDDLRLRAB'
|
|
|
|
|
self.assertEqual(Bytes(testcase).hex(), testcase.hex(),
|
|
|
|
|
f"Bytes({testcase}).hex() == {testcase}.hex()")
|
|
|
|
|
tests = [['55:55:44:44:4c:52:4c:52:41:42', ":", 1],
|
|
|
|
|
['55:55:44:44:4c:52:4c:52:41:42', ":", -1],
|
|
|
|
|
['5555:44444c52:4c524142', ":", 4],
|
|
|
|
|
['55554444:4c524c52:4142', ":", -4],
|
|
|
|
|
['55 - 55 - 44 - 44 - 4c - 52 - 4c - 52 - 41 - 42', " - ",
|
|
|
|
|
1],
|
|
|
|
|
['55, 55, 44, 44, 4c, 52, 4c, 52, 41, 42', ", ", 1],
|
|
|
|
|
['5555, 44444c52, 4c524142', ", ", 4],
|
|
|
|
|
['55554444, 4c524c52, 4142', ", ", -4]
|
|
|
|
|
]
|
|
|
|
|
for subt in tests:
|
|
|
|
|
self.assertEqual(Bytes(testcase).hex(sep=subt[1],
|
|
|
|
|
bytes_per_sep=subt[2]),
|
|
|
|
|
subt[0],
|
|
|
|
|
f"Bytes({testcase}).hex(sep='{subt[1]}', " +
|
|
|
|
|
f"bytes_per_sep={subt[2]}) == {subt[0]}")
|
|
|
|
|
|
|
|
|
|
def test_comparison_operators(self):
|
|
|
|
|
"""
|
|
|
|
|