File: test_parse_id.py

package info (click to toggle)
python-transmission-rpc 7.0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: python: 2,605; sh: 9; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 967 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
import pytest

from transmission_rpc.client import _parse_torrent_id, _parse_torrent_ids

example_hash = "51ba7d0dd45ab9b9564329c33f4f97493b677924"


@pytest.mark.parametrize("arg", [float(1), "non-hash-string"])
def test_parse_id_raise(arg):
    with pytest.raises(ValueError, match=f"{arg} is not valid torrent id"):
        _parse_torrent_id(arg)


@pytest.mark.parametrize(
    ("arg", "expected"),
    [
        ("recently-active", "recently-active"),
        (example_hash, [example_hash]),
        ((2, example_hash), [2, example_hash]),
        (3, [3]),
        (None, []),
    ],
)
def test_parse_torrent_ids(arg, expected):
    assert _parse_torrent_ids(arg) == expected, f"parse_torrent_ids({arg}) != {expected}"


@pytest.mark.parametrize("arg", ["not-recently-active", "non-hash-string", -1, 1.1, "5:10", "5,6,8,9,10"])
def test_parse_torrent_ids_value_error(arg):
    with pytest.raises(ValueError, match="torrent id"):
        _parse_torrent_ids(arg)