Cotton code
32 lines · 1.5 KB · PythonRaw
"""Synthetic checks of the pinned SCOWL category selection."""import iofrom pathlib import Pathimport tarfileimport tempfileimport unittestfrom words import termsclass WordSelection(unittest.TestCase):    def test_word_categories_exclude_names_and_preserve_common_capitalized_words(self):        # RULE: A real English word protects dictation from name snapping, while SCOWL's personal-name categories must never make a non-word a word.        with tempfile.TemporaryDirectory() as tmp:            source = Path(tmp) / "scowl.tar.gz"            with tarfile.open(source, "w:gz") as archive:                for filename, text in [("english-words.10", "hello\nroan\nrose\n"),                                       ("english-words.80", "roan\ncafé\n"),                                       ("english-contractions.35", "don't\n"),                                       ("english-upper.35", "Monday\n"),                                       ("english-upper.50", "Aaron\nXavier\n"),                                       ("english-proper-names.10", "Priyanka\n"),                                       ("english-abbreviations.10", "XYQ\n")]:                    data = text.encode("latin-1")                    member = tarfile.TarInfo("scowl/final/" + filename)                    member.size = len(data)                    archive.addfile(member, io.BytesIO(data))            self.assertEqual(terms(source), ["café", "don't", "hello", "monday", "roan", "rose"])if __name__ == "__main__":    unittest.main()