# -*- coding: utf-8 -*- """Run: python -m pytest test_normalize.py (or: python test_normalize.py)""" import json, os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from bambara_normalize import normalize, tokens HERE = os.path.dirname(os.path.abspath(__file__)) def test_examples(): with open(os.path.join(HERE, "examples.jsonl"), encoding="utf-8") as f: for line in f: e = json.loads(line) assert normalize(e["input"]) == e["expected"], (e["input"], normalize(e["input"]), e["expected"]) def test_rules(): assert normalize("Ne bè taa Sikasso nyɛ fɛ") == "ne bɛ taa sikaso ɲɛ fɛ" assert normalize("nganiya") == "ŋaniya" assert normalize("fanga") == "fanga" # inner n+g is left alone assert normalize("kà kɛ́") == "ka kɛ" # tone marks removed assert normalize("K’ a fɔ!") == "k'a fɔ" # apostrophe unified and attached assert normalize("bè", accents_as_open_vowels=False, lexical=False) == "be" assert normalize("nyɛ", old_orthography=False) == "nyɛ" assert normalize("A bɛ so kɔnɔ.", punctuation=False) == "a bɛ so kɔnɔ." assert tokens("A bɛ so kɔnɔ.") == ["a", "bɛ", "so", "kɔnɔ"] if __name__ == "__main__": test_examples(); test_rules(); print("OK")