@@ -151,10 +151,50 @@ def test_checks_fuzzy() -> None:
151151 # be sure we have one file in result
152152 assert len (result ) == 1
153153
154- # the file has 11 errors (with the fuzzy string)
154+ # the file has 10 errors (with the fuzzy string)
155155 assert len (result [0 ]) == 10
156156
157157
158+ def test_error_on_fuzzy () -> None :
159+ """Test error_on_fuzzy option that raises an error when fuzzy strings are found."""
160+ po_check = PoCheck ()
161+ # disable all tests and enable only "error_on_fuzzy"
162+ po_check .checks = dict .fromkeys (po_check .checks , False )
163+ po_check .set_check ("error_on_fuzzy" )
164+ result = po_check .check_files ([local_path ("fr_errors.po" )])
165+
166+ # be sure we have one file in result
167+ assert len (result ) == 1
168+
169+ # the file has 1 fuzzy string
170+ assert len (result [0 ]) == 1
171+
172+ # check the error report
173+ report = result [0 ][0 ]
174+ assert report .idmsg == "fuzzy"
175+ assert report .message == "fuzzy string"
176+ assert report .fuzzy is True
177+ assert "fr_errors.po" in report .filename
178+ assert report .line == 58 # Line where the fuzzy string starts
179+ assert report .mid == "Tested 3"
180+ assert report .mstr == "Testé 3."
181+
182+
183+ def test_error_on_fuzzy_no_fuzzy_strings () -> None :
184+ """Test error_on_fuzzy option when there are no fuzzy strings."""
185+ po_check = PoCheck ()
186+ # disable all tests and enable only "error_on_fuzzy"
187+ po_check .checks = dict .fromkeys (po_check .checks , False )
188+ po_check .set_check ("error_on_fuzzy" )
189+ result = po_check .check_files ([local_path ("fr.po" )])
190+
191+ # be sure we have one file in result
192+ assert len (result ) == 1
193+
194+ # the file has 10 errors (no fuzzy strings)
195+ assert len (result [0 ]) == 0
196+
197+
158198def test_checks_noqa () -> None :
159199 """Test checks on a gettext file including `noqa`-commented lines."""
160200 po_check = PoCheck ()
0 commit comments