Download tests/test_phase4_fertility.py from Anupam-Rawat-IITB/code-switch-mtp: direct link, hf CLI and curl.
- Browser
- Download file 3.11 kB
-
https://huggingface.co/Anupam-Rawat-IITB/code-switch-mtp/resolve/main/tests/test_phase4_fertility.py
- Command line
-
hf download hf://Anupam-Rawat-IITB/code-switch-mtp/tests/test_phase4_fertility.py
-
curl -L -o test_phase4_fertility.py https://huggingface.co/Anupam-Rawat-IITB/code-switch-mtp/resolve/main/tests/test_phase4_fertility.py
3.11 kB
| """Tests for the IAST / ISO 15919 romanizer behind the within-model fertility sweep.""" | |
| from scripts.phase4_fertility_romanize import iter_romanized, roundtrip_scheme, romanize_scheme, sentence_round_trips | |
| from src.data.itrans_transliterate import _roundtrip_for_check, romanize | |
| def test_generic_path_reproduces_phase1_itrans_exactly(): | |
| """The scheme-generic code must be the Phase 1 ITRANS path when given ITRANS.""" | |
| for s in ["भारत एक विशाल देश है।", "मैं बाज़ार जा रहा हूँ", "क्योंकि एक उच्च Amex व्यापारी छूट शुल्क लेता है"]: | |
| assert romanize_scheme(s, "ITRANS") == romanize(s) | |
| assert roundtrip_scheme(s, "ITRANS") == _roundtrip_for_check(s) | |
| def test_iast_and_iso_round_trip_plain_hindi(): | |
| for scheme in ("IAST", "ISO"): | |
| assert sentence_round_trips("भारत एक विशाल देश है।", scheme) | |
| assert sentence_round_trips("मैं बाज़ार जा रहा हूँ", scheme) | |
| def test_iast_and_iso_use_diacritics(): | |
| assert romanize_scheme("भारत एक विशाल देश है।", "IAST") == "bhārata eka viśāla deśa hai." | |
| assert romanize_scheme("भारत एक विशाल देश है।", "ISO") == "bhārata ēka viśāla dēśa hai." | |
| def test_embedded_latin_word_is_left_untouched(): | |
| s = "क्योंकि एक उच्च Amex व्यापारी छूट शुल्क लेता है" | |
| for scheme in ("IAST", "ISO"): | |
| assert "Amex" in romanize_scheme(s, scheme) | |
| assert sentence_round_trips(s, scheme) | |
| def test_quotation_mark_that_doubles_as_avagraha_round_trips(): | |
| """Regression guard: IAST writes avagraha as ' and ISO as ’, so without | |
| routing those quotation marks around the converter 'वो' came back as ऽवोऽ. | |
| """ | |
| assert sentence_round_trips("उसने कहा 'वो आयेगी' और चली गई।", "IAST") | |
| assert sentence_round_trips("उसने कहा ‘वो आयेगी’ और चली गई।", "ISO") | |
| def test_quotation_mark_survives_forward_romanization_unchanged(): | |
| assert romanize_scheme("उसने कहा 'वो आयेगी'", "IAST").count("'") == 2 | |
| assert romanize_scheme("उसने कहा ‘वो आयेगी’", "ISO").count("’") == 1 | |
| def test_real_avagraha_still_round_trips(): | |
| for scheme in ("IAST", "ISO"): | |
| assert sentence_round_trips("सोऽहम्", scheme) | |
| def test_iter_romanized_preserves_order_and_is_lazy(): | |
| pulled = [] | |
| def source(): | |
| for i in range(10): | |
| pulled.append(i) | |
| yield f"शब्द {i}" | |
| stream = iter_romanized(source(), "IAST", pool=None, batch_docs=3) | |
| first_two = [next(stream), next(stream)] | |
| assert first_two == ["śabda 0", "śabda 1"] | |
| assert len(pulled) == 3 # only the first batch was read | |
| assert list(stream) == [f"śabda {i}" for i in range(2, 10)] | |