File: test_two_way_dict.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (45 lines) | stat: -rw-r--r-- 871 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
import pytest

from textual._two_way_dict import TwoWayDict


@pytest.fixture
def two_way_dict():
    return TwoWayDict(
        {
            1: 10,
            2: 20,
            3: 30,
        }
    )


def test_get(two_way_dict):
    assert two_way_dict.get(1) == 10


def test_get_key(two_way_dict):
    assert two_way_dict.get_key(30) == 3


def test_set_item(two_way_dict):
    two_way_dict[40] = 400
    assert two_way_dict.get(40) == 400
    assert two_way_dict.get_key(400) == 40


def test_len(two_way_dict):
    assert len(two_way_dict) == 3


def test_delitem(two_way_dict):
    assert two_way_dict.get(3) == 30
    assert two_way_dict.get_key(30) == 3
    del two_way_dict[3]
    assert two_way_dict.get(3) is None
    assert two_way_dict.get_key(30) is None


def test_contains(two_way_dict):
    assert 1 in two_way_dict
    assert 10 not in two_way_dict