File: test_humanize_integer_sequence.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 (28 lines) | stat: -rw-r--r-- 714 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
import pytest

from eth_utils import (
    humanize_integer_sequence,
)


@pytest.mark.parametrize(
    "seq,expected",
    (
        ((), "(empty)"),
        ((1,), "1"),
        ((2,), "2"),
        ((10,), "10"),
        ((1, 2, 3), "1-3"),
        (range(6), "0-5"),
        ((1, 2, 3, 7, 8, 9), "1-3|7-9"),
        ((1, 2, 3, 5, 7, 8, 9), "1-3|5|7-9"),
        ((1, 3, 4, 5, 7, 8, 9), "1|3-5|7-9"),
        ((1, 3, 4, 5, 9), "1|3-5|9"),
        # should accept a generator
        ((_ for _ in range(0)), "(empty)"),
        ((i for i in (1, 2, 3, 7, 8, 10)), "1-3|7-8|10"),
    ),
)
def test_humanize_integer_sequence(seq, expected):
    actual = humanize_integer_sequence(seq)
    assert actual == expected