[cad161]: / tests / test_conjugator.py

Download this file

81 lines (62 with data), 2.3 kB

 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytest
pytest.importorskip("mlconjug3")
from mlconjug3 import Conjugator # noqa: E402
from edsnlp.conjugator import ( # noqa: E402
conjugate,
conjugate_verb,
get_conjugated_verbs,
)
pytestmark = pytest.mark.filterwarnings("ignore")
def test_conjugate_verb():
conjugator = Conjugator("fr")
tests = [
(("aimer", "Indicatif", "Présent", "1s"), "aime"),
(("aimer", "Indicatif", "Présent", "2s"), "aimes"),
(("aimer", "Indicatif", "Présent", "1p"), "aimons"),
(("aimer", "Indicatif", "Présent", "2p"), "aimez"),
(("aimer", "Indicatif", "Présent", "3p"), "aiment"),
]
verb = "aimer"
df = conjugate_verb(verb, conjugator=conjugator)
for (v, m, t, p), term in tests:
row = df.query("verb == @v & mode == @m & tense == @t & person == @p").iloc[0]
assert row.term == term
def test_conjugate():
tests = [
(("aimer", "Indicatif", "Présent", "1s"), "aime"),
(("aimer", "Indicatif", "Présent", "2s"), "aimes"),
(("aimer", "Indicatif", "Présent", "1p"), "aimons"),
(("aimer", "Indicatif", "Présent", "2p"), "aimez"),
(("aimer", "Indicatif", "Présent", "3p"), "aiment"),
(("convaincre", "Indicatif", "Présent", "2s"), "convaincs"),
(("convaincre", "Indicatif", "Présent", "1s"), "convaincs"),
(("convaincre", "Indicatif", "Présent", "1p"), "convainquons"),
(("convaincre", "Indicatif", "Présent", "2p"), "convainquez"),
(("convaincre", "Indicatif", "Présent", "3p"), "convainquent"),
]
conjugate("aimer")
df = conjugate(["aimer", "convaincre"])
for (v, m, t, p), term in tests:
row = df.query("verb == @v & mode == @m & tense == @t & person == @p").iloc[0]
assert row.term == term
def test_get_conjugated_verbs():
terms = get_conjugated_verbs(
["aimer", "convaincre"],
matches=[dict(mode="Indicatif", tense="Présent")],
)
get_conjugated_verbs(
"aimer",
matches=dict(mode="Indicatif", tense="Présent"),
)
assert set(terms) == {
"aime",
"aimes",
"aimons",
"aimez",
"aiment",
"convainc",
"convaincs",
"convainquons",
"convainquez",
"convainquent",
}