"""The gold answers of this bundle. The corpus is the only place where a mistake common to both readers can show up: the two readers share the lexicon, the atomizer and the templates, so a wrong description of a variety is invisible to the topology and visible only here, in a sentence a person wrote and checked. """ import pytest from lgstratum import canonical, corpus, lexicon ITEMS = corpus.load() IDS = [str(item["id"]) for item in ITEMS] BY_ID = {str(item["id"]): item for item in ITEMS} def test_every_item_has_its_own_identifier_and_a_question(): assert IDS and len(set(IDS)) == len(IDS) for item in ITEMS: assert str(item.get("question", "")).strip(), item.get("id") assert str(item.get("lang", "")) in lexicon.codes(), item.get("id") assert str(item.get("kind", "")), item.get("id") def test_every_covered_language_is_asked_and_answered(): asked = {str(item["lang"]) for item in ITEMS} assert asked == set(lexicon.codes()), (asked, lexicon.codes()) def test_every_kind_the_math_stratum_understands_is_asked_in_some_language(): asked = {str(item["kind"]) for item in ITEMS if item.get("expect", {}).get("sentence")} assert set(canonical.KINDS) <= asked, sorted(set(canonical.KINDS) - asked) def test_every_language_is_also_asked_about_something_it_does_not_cover(): # A stratum that always answers is a stratum that always guesses: the negative items are what # keep the abstentions real, in every variety at once. for lang in lexicon.codes(): negatives = [item for item in ITEMS if str(item["lang"]) == lang and str(item.get("kind")) == "negative"] assert negatives, lang def test_the_corpus_keeps_a_record_of_what_it_knows_it_cannot_do(): # Two kinds of limitation are written into the gold data on purpose: the varieties where only one # reader gets the joint (SINGLE, one level of assurance), and the questions whose mathematics is # out of reach of the math stratum, where the reading is agreed and the answer still does not come. single = [item for item in ITEMS if (item.get("expect") or {}).get("state") == "SINGLE"] silent = [item for item in ITEMS if (item.get("expect") or {}).get("state") in ("AGREED", "PASSTHROUGH") and (item.get("expect") or {}).get("no_answer") is True] assert single, "no item records the limit of one reader only" assert silent, "no item records a question the math stratum cannot answer" @pytest.mark.parametrize("item_id", IDS) def test_the_gold_answer_of_this_item_is_met(item_id): outcome = corpus.outcome(BY_ID[item_id]) assert outcome["ok"] is True, (item_id, outcome["state"], outcome["assurance"], outcome["problems"]) def test_no_item_ever_reaches_the_level_of_the_math_stratum(): for item in ITEMS: expect = item.get("expect") or {} assert int(expect.get("max_assurance", 0) or 0) < 3, item["id"] assert int(expect.get("min_assurance", 0) or 0) < 3, item["id"]