forked from ChelseaKR/homeroom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ask_guards.py
More file actions
165 lines (138 loc) · 5.68 KB
/
Copy pathtest_ask_guards.py
File metadata and controls
165 lines (138 loc) · 5.68 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""The lexical guards: judgment language, numbers, absence, years."""
from __future__ import annotations
import pytest
from homeroom.ask.guards import (
judgment_hits,
number_forms,
numbers_in,
renders_absence_as_value,
says_not_published,
year_tokens,
)
@pytest.mark.parametrize(
"sentence",
[
"This is a good school.",
"Attendance here is better than the district.",
"It ranks among the top schools in the county.",
"I would give it a B+.",
"Overall grade: A",
"On a scale out of 10 it is a 7.",
"The school scores well.",
"Its rating is strong.",
"I recommend enrolling.",
"You should send your child here.",
"This is one of the worst schools around.",
"Above average for the district.",
"It outperforms the state.",
"Es una buena escuela.",
"La asistencia es mejor que en el distrito.",
"Le doy una calificación de 8.",
"Su puntaje es alto.",
"Recomiendo inscribir a su hijo.",
"Está por encima del promedio.",
"Es una de las mejores escuelas.",
"Es peor que el estado.",
],
)
def test_judgment_language_is_caught_in_both_languages(sentence: str) -> None:
assert judgment_hits(sentence), sentence
@pytest.mark.parametrize(
"sentence",
[
"Grade 3 has 45 students.",
"The chronic absenteeism rate is 12.5%, higher than the district's 11%.",
"The rate is lower than the statewide figure.",
"The state withheld this figure to protect student privacy.",
"El grado 3 tiene 45 estudiantes.",
"La tasa es más alta que la del distrito.",
"El estado retuvo esta cifra para proteger la privacidad.",
"Enrollment on Census Day was 512 students.",
"La escuela mejoró su sistema de datos.",
],
)
def test_plain_figures_and_directions_are_not_judgment(sentence: str) -> None:
assert judgment_hits(sentence) == [], sentence
def test_numbers_are_extracted_and_normalised() -> None:
assert numbers_in("1,234 students, 12.5% and 7") == ["1234", "12.5", "7"]
assert numbers_in("no digits here") == []
assert numbers_in("Grade 3: 45") == ["3", "45"]
def test_academic_years_are_not_read_as_two_numbers() -> None:
assert numbers_in("in 2024-25 the rate was 12.5%") == ["12.5"]
assert numbers_in("en 2024\u201325 la tasa fue 12.5%") == ["12.5"]
assert numbers_in("2025/26 enrollment: 512") == ["512"]
assert year_tokens("2024-25") == {"2024-25", "2024", "25", "2025"}
assert year_tokens("2025-26") == {"2025-26", "2025", "26", "2026"}
def test_number_forms_are_exact_not_rounded() -> None:
assert number_forms(512.0) == {"512"}
assert "12.5" in number_forms(12.5)
assert "12" not in number_forms(12.5)
assert "13" not in number_forms(12.5)
@pytest.mark.parametrize(
"sentence",
[
"This figure was not published.",
"The state withheld it to protect privacy.",
"CDE did not publish a figure for this group.",
"No figure is published for this school.",
"The rate for this school has not been published.",
"This figure is not available for the school.",
"El estado no publicó esta cifra.",
"Esta cifra fue retenida para proteger la privacidad.",
"No se publicó ningún dato para este grupo.",
"Sin dato publicado.",
],
)
def test_absence_stated_honestly_is_recognised(sentence: str) -> None:
assert says_not_published(sentence), sentence
@pytest.mark.parametrize(
"sentence",
[
"There are zero English learners.",
"None of the students are homeless.",
"No students in this group.",
"The rate is 0%.",
"Hay cero estudiantes.",
"Ningún estudiante es migrante.",
"No hay estudiantes en este grupo.",
],
)
def test_absence_rendered_as_a_value_is_caught(sentence: str) -> None:
assert renders_absence_as_value(sentence), sentence
def test_an_honest_absence_sentence_is_not_a_value() -> None:
assert not renders_absence_as_value(
"The figure for this group was withheld to protect student privacy."
)
assert not says_not_published("The rate is 12.5%.")
def test_an_explicit_negation_of_the_zero_reading_is_not_a_value() -> None:
assert not renders_absence_as_value(
"The state withholds it to protect privacy, not because there are no students."
)
assert renders_absence_as_value("There are no students in this group.")
@pytest.mark.parametrize(
"sentence",
[
"La escuela no aparece en el archivo de ausentismo.",
"No hay datos publicados para esta escuela.",
"El archivo no incluye a esta escuela.",
"El estado no la menciona en el archivo.",
],
)
def test_spanish_ways_of_saying_the_file_has_nothing(sentence: str) -> None:
assert says_not_published(sentence), sentence
@pytest.mark.parametrize(
"sentence",
[
"The state withholds it to protect privacy, not because the number is zero.",
"It is not possible to say whether the rate is zero, small, or large.",
"Withheld to protect privacy, not because no students were absent.",
"A withheld figure does not mean zero students.",
"Retenido para proteger la privacidad, no porque haya cero estudiantes.",
"No es posible saber si hay cero estudiantes ausentes.",
],
)
def test_a_denial_of_the_zero_reading_is_not_a_value(sentence: str) -> None:
assert not renders_absence_as_value(sentence), sentence
def test_withholds_and_suppresses_are_absence_phrases() -> None:
assert says_not_published("The state withholds figures like this one.")
assert says_not_published("CDE suppresses the cell.")