summaryrefslogtreecommitdiff
path: root/tests/common/hex.py
blob: f76b6a848692914223263cc887b82854c0d8ef20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

from chrysacase import ChrysalideTestCase
from pychrysalide.common import encode_hex, decode_hex_digit


class TestHexValues(ChrysalideTestCase):
    """TestCase for common hexadecimal features*"""

    def testHexEncoding(self):
        """Convert data to hex string."""

        ref = b'ABC'

        self.assertEqual(encode_hex(ref), ref.hex())

        ref = 'ABC'

        self.assertEqual(encode_hex(ref), bytes(ref, 'ascii').hex())

        ref = 'ABC'

        self.assertEqual(encode_hex(ref, False), bytes(ref, 'ascii').hex().upper())


    def testHexDecoding(self):
        """Convert a hex string to value."""

        self.assertEqual(decode_hex_digit('A'), 0xa)