File: test_result.py

package info (click to toggle)
python-parse 1.20.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 204 kB
  • sloc: python: 1,518; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (3)
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
34
35
36
37
38
import pytest

import parse


def test_fixed_access():
    r = parse.Result((1, 2), {}, None)
    assert r[0] == 1
    assert r[1] == 2
    with pytest.raises(IndexError):
        r[2]
    with pytest.raises(KeyError):
        r["spam"]


def test_slice_access():
    r = parse.Result((1, 2, 3, 4), {}, None)
    assert r[1:3] == (2, 3)
    assert r[-5:5] == (1, 2, 3, 4)
    assert r[:4:2] == (1, 3)
    assert r[::-2] == (4, 2)
    assert r[5:10] == ()


def test_named_access():
    r = parse.Result((), {"spam": "ham"}, None)
    assert r["spam"] == "ham"
    with pytest.raises(KeyError):
        r["ham"]
    with pytest.raises(IndexError):
        r[0]


def test_contains():
    r = parse.Result(("cat",), {"spam": "ham"}, None)
    assert "spam" in r
    assert "cat" not in r
    assert "ham" not in r