File: test_is_hexstr.py

package info (click to toggle)
python-eth-utils 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,140 kB
  • sloc: python: 5,985; makefile: 238
file content (33 lines) | stat: -rw-r--r-- 954 bytes parent folder | download
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
29
30
31
32
33
import pytest

from eth_utils import (
    is_hexstr,
)


@pytest.mark.parametrize(
    "value,expected",
    (
        ("", False),  # empty string
        ("0x", True),  # empty string
        ("0X", True),  # empty string
        ("abcdef1234567890", True),
        ("ABCDEF1234567890", True),
        ("AbCdEf1234567890", True),
        ("0xabcdef1234567890", True),
        ("0xABCDEF1234567890", True),
        ("0xAbCdEf1234567890", True),
        ("12345", True),  # odd length
        ("0x12345", True),  # odd length
        ("123456xx", False),  # non-hex character
        ("0x123456xx", False),  # non-hex character
        ("0\u0080", False),  # triggers different exceptions in py2 and py3
        (1, False),  # int
        (b"", False),  # bytes
        ({}, False),  # dictionary
        (lambda: None, False),  # lambda function
    ),
)
def test_is_hexstr(value, expected):
    actual = is_hexstr(value)
    assert actual is expected