• 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_prediction.py
1
from hashlib import md5
7✔
2

3
import pytest
7✔
4

5
import dawg_python
7✔
6

7
from .utils import data_path
7✔
8

9

10
def encode(w):
7✔
11
    code = md5(w.encode("utf8"))
7✔
12
    return tuple([ord(c) for c in code.hexdigest()])[:4]
7✔
13

14

15
class TestPrediction:
7✔
16
    REPLACES = dawg_python.DAWG.compile_replaces({"Е": "Ё"})
7✔
17

18
    DATA = ["ЁЖИК", "ЁЖИКЕ", "ЁЖ", "ДЕРЕВНЯ", "ДЕРЁВНЯ", "ЕМ", "ОЗЕРА", "ОЗЁРА", "ОЗЕРО"]
7✔
19
    SUITE = [
7✔
20
        ("УЖ", []),
21
        ("ЕМ", ["ЕМ"]),
22
        ("ЁМ", []),
23
        ("ЁЖ", ["ЁЖ"]),
24
        ("ЕЖ", ["ЁЖ"]),
25
        ("ЁЖИК", ["ЁЖИК"]),
26
        ("ЕЖИКЕ", ["ЁЖИКЕ"]),
27
        ("ДЕРЕВНЯ", ["ДЕРЕВНЯ", "ДЕРЁВНЯ"]),
28
        ("ДЕРЁВНЯ", ["ДЕРЁВНЯ"]),
29
        ("ОЗЕРА", ["ОЗЕРА", "ОЗЁРА"]),
30
        ("ОЗЕРО", ["ОЗЕРО"]),
31
    ]
32

33
    SUITE_ITEMS = [
7✔
34
        (
35
            it[0],  # key
36
            [(w, [(len(w),)]) for w in it[1]],  # item, value pair
37
        )
38
        for it in SUITE
39
    ]
40

41
    SUITE_VALUES = [
7✔
42
        (
43
            it[0],  # key
44
            [[(len(w),)] for w in it[1]],
45
        )
46
        for it in SUITE
47
    ]
48

49
    def record_dawg(self):
7✔
50
        path = data_path("small", "prediction-record.dawg")
7✔
51
        return dawg_python.RecordDAWG("=H").load(path)
7✔
52

53
    @pytest.mark.parametrize(("word", "prediction"), SUITE)
7✔
54
    def test_dawg_prediction(self, word, prediction):
7✔
55
        d = dawg_python.DAWG().load(data_path("small", "prediction.dawg"))
7✔
56
        assert d.similar_keys(word, self.REPLACES) == prediction
7✔
57

58
    @pytest.mark.parametrize(("word", "prediction"), SUITE)
7✔
59
    def test_record_dawg_prediction(self, word, prediction):
7✔
60
        d = self.record_dawg()
7✔
61
        assert d.similar_keys(word, self.REPLACES) == prediction
7✔
62

63
    @pytest.mark.parametrize(("word", "prediction"), SUITE_ITEMS)
7✔
64
    def test_record_dawg_items(self, word, prediction):
7✔
65
        d = self.record_dawg()
7✔
66
        assert d.similar_items(word, self.REPLACES) == prediction
7✔
67

68
    @pytest.mark.parametrize(("word", "prediction"), SUITE_VALUES)
7✔
69
    def test_record_dawg_items_values(self, word, prediction):
7✔
70
        d = self.record_dawg()
7✔
71
        assert d.similar_item_values(word, self.REPLACES) == prediction
7✔
72

73

74
class TestMultiValuedPrediction:
7✔
75
    REPLACES = dawg_python.DAWG.compile_replaces({"е": ["ё", "ѣ"], "и": "і"})
7✔
76

77
    DATA = [
7✔
78
        "хлѣб",
79
        "ёлка",
80
        "ель",
81
        "лѣс",
82
        "лѣсное",
83
        "всё",
84
        "всѣ",
85
        "бѣлёная",
86
        "изобрѣтён",
87
        "лев",
88
        "лёв",
89
        "лѣв",
90
        "вѣнскій",
91
    ]
92

93
    SUITE = [
7✔
94
        ("осел", []),
95
        ("ель", ["ель"]),
96
        ("ёль", []),
97
        ("хлеб", ["хлѣб"]),
98
        ("елка", ["ёлка"]),
99
        ("лесное", ["лѣсное"]),
100
        ("лесноё", []),
101
        ("лёсное", []),
102
        ("изобретен", ["изобрѣтён"]),
103
        ("беленая", ["бѣлёная"]),
104
        ("белёная", ["бѣлёная"]),
105
        ("бѣленая", ["бѣлёная"]),
106
        ("бѣлёная", ["бѣлёная"]),
107
        ("белѣная", []),
108
        ("бѣлѣная", []),
109
        ("все", ["всё", "всѣ"]),
110
        ("лев", ["лев", "лёв", "лѣв"]),
111
        ("венский", ["вѣнскій"]),
112
    ]
113

114
    SUITE_ITEMS = [
7✔
115
        (
116
            it[0],  # key
117
            [
118
                (w, [encode(w)])  # item, value pair
119
                for w in it[1]
120
            ],
121
        )
122
        for it in SUITE
123
    ]
124

125
    SUITE_VALUES = [
7✔
126
        (
127
            it[0],  # key
128
            [[encode(w)] for w in it[1]],
129
        )
130
        for it in SUITE
131
    ]
132

133
    def record_dawg(self):
7✔
134
        path = data_path("small", "prediction1917-record.dawg")
7✔
135
        return dawg_python.RecordDAWG("=HHHH").load(path)
7✔
136

137
    @pytest.mark.parametrize(("word", "prediction"), SUITE)
7✔
138
    def test_dawg_prediction(self, word, prediction):
7✔
139
        d = dawg_python.DAWG().load(data_path("small", "prediction1917.dawg"))
7✔
140
        assert d.similar_keys(word, self.REPLACES) == prediction
7✔
141

142
    @pytest.mark.parametrize(("word", "prediction"), SUITE)
7✔
143
    def test_record_dawg_prediction(self, word, prediction):
7✔
144
        d = self.record_dawg()
7✔
145
        assert d.similar_keys(word, self.REPLACES) == prediction
7✔
146

147
    @pytest.mark.parametrize(("word", "prediction"), SUITE_ITEMS)
7✔
148
    def test_record_dawg_items(self, word, prediction):
7✔
149
        d = self.record_dawg()
7✔
150
        assert d.similar_items(word, self.REPLACES) == prediction
7✔
151

152
    @pytest.mark.parametrize(("word", "prediction"), SUITE_VALUES)
7✔
153
    def test_record_dawg_items_values(self, word, prediction):
7✔
154
        d = self.record_dawg()
7✔
155
        assert d.similar_item_values(word, self.REPLACES) == prediction
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