• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pymorphy2-fork / DAWG-Python / 14779646156

01 May 2025 05:04PM UTC coverage: 89.925%. Remained the same
14779646156

Pull #46

github

web-flow
Merge 13b24eede into bf6170229
Pull Request #46: Bump typing-extensions from 4.12.2 to 4.13.2

204 of 237 branches covered (86.08%)

Branch coverage included in aggregate %.

635 of 696 relevant lines covered (91.24%)

6.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/tests/test_payload_dawg.py
1
import pytest
7✔
2

3
import dawg_python
7✔
4

5
from .utils import data_path
7✔
6

7

8
class TestBytesDAWG:
7✔
9
    DATA = (
7✔
10
        ("foo", b"data1"),
11
        ("bar", b"data2"),
12
        ("foo", b"data3"),
13
        ("foobar", b"data4"),
14
    )
15

16
    def dawg(self):
7✔
17
        return dawg_python.BytesDAWG().load(data_path("small", "bytes.dawg"))
7✔
18

19
    def test_contains(self):
7✔
20
        d = self.dawg()
7✔
21
        for key, _val in self.DATA:
7✔
22
            assert key in d
7✔
23

24
        assert "food" not in d
7✔
25
        assert "x" not in d
7✔
26
        assert "fo" not in d
7✔
27

28
    def test_getitem(self):
7✔
29
        d = self.dawg()
7✔
30

31
        assert d["foo"] == [b"data1", b"data3"]
7✔
32
        assert d["bar"] == [b"data2"]
7✔
33
        assert d["foobar"] == [b"data4"]
7✔
34

35
    def test_getitem_missing(self):
7✔
36
        d = self.dawg()
7✔
37

38
        with pytest.raises(KeyError):
7✔
39
            d["x"]
7✔
40

41
        with pytest.raises(KeyError):
7✔
42
            d["food"]
7✔
43

44
        with pytest.raises(KeyError):
7✔
45
            d["foobarz"]
7✔
46

47
        with pytest.raises(KeyError):
7✔
48
            d["f"]
7✔
49

50
    def test_keys(self):
7✔
51
        d = self.dawg()
7✔
52
        assert d.keys() == ["bar", "foo", "foo", "foobar"]
7✔
53

54
    def test_iterkeys(self):
7✔
55
        d = self.dawg()
7✔
56
        assert list(d.iterkeys()) == d.keys()
7✔
57

58
    def test_key_completion(self):
7✔
59
        d = self.dawg()
7✔
60
        assert d.keys("fo") == ["foo", "foo", "foobar"]
7✔
61

62
    def test_items(self):
7✔
63
        d = self.dawg()
7✔
64
        assert d.items() == sorted(self.DATA)
7✔
65

66
    def test_iteritems(self):
7✔
67
        d = self.dawg()
7✔
68
        assert list(d.iteritems("xxx")) == []
7✔
69
        assert list(d.iteritems("fo")) == d.items("fo")
7✔
70
        assert list(d.iteritems()) == d.items()
7✔
71

72
    def test_items_completion(self):
7✔
73
        d = self.dawg()
7✔
74
        assert d.items("foob") == [("foobar", b"data4")]
7✔
75

76
    def test_prefixes(self):
7✔
77
        d = self.dawg()
7✔
78
        assert d.prefixes("foobarz") == ["foo", "foobar"]
7✔
79
        assert d.prefixes("x") == []
7✔
80
        assert d.prefixes("bar") == ["bar"]
7✔
81

82

83
class TestRecordDAWG:
7✔
84
    STRUCTURED_DATA = (
7✔
85
        ("foo", (3, 2, 256)),
86
        ("bar", (3, 1, 0)),
87
        ("foo", (3, 2, 1)),
88
        ("foobar", (6, 3, 0)),
89
    )
90

91
    def dawg(self):
7✔
92
        path = data_path("small", "record.dawg")
7✔
93
        return dawg_python.RecordDAWG(">3H").load(path)
7✔
94

95
    def test_getitem(self):
7✔
96
        d = self.dawg()
7✔
97
        assert d["foo"] == [(3, 2, 1), (3, 2, 256)]
7✔
98
        assert d["bar"] == [(3, 1, 0)]
7✔
99
        assert d["foobar"] == [(6, 3, 0)]
7✔
100

101
    def test_getitem_missing(self):
7✔
102
        d = self.dawg()
7✔
103

104
        with pytest.raises(KeyError):
7✔
105
            d["x"]
7✔
106

107
        with pytest.raises(KeyError):
7✔
108
            d["food"]
7✔
109

110
        with pytest.raises(KeyError):
7✔
111
            d["foobarz"]
7✔
112

113
        with pytest.raises(KeyError):
7✔
114
            d["f"]
7✔
115

116
    def test_record_items(self):
7✔
117
        d = self.dawg()
7✔
118
        assert d.items() == sorted(self.STRUCTURED_DATA)
7✔
119

120
    def test_record_keys(self):
7✔
121
        d = self.dawg()
7✔
122
        assert d.keys() == ["bar", "foo", "foo", "foobar"]
7✔
123

124
    def test_record_keys_prefix(self):
7✔
125
        d = self.dawg()
7✔
126
        assert d.keys("fo") == ["foo", "foo", "foobar"]
7✔
127
        assert d.keys("bar") == ["bar"]
7✔
128
        assert d.keys("barz") == []
7✔
129

130
    def test_prefixes(self):
7✔
131
        d = self.dawg()
7✔
132
        assert d.prefixes("foobarz") == ["foo", "foobar"]
7✔
133
        assert d.prefixes("x") == []
7✔
134
        assert d.prefixes("bar") == ["bar"]
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc