Пример #1
0
    def test_possessive(self):
        test_data = [
            ("Tom's", "Toms'"),
            ("book's", "books'"),
            ("brother's", "brothers'"),
            ("about Tom's", "about Toms'"),
            ("beneath book's", "beneath books'"),
            ("at brother's", "at brothers'"),
            ("  Tom's", "  Toms'"),
            (" book's ", " books' "),
            ("  brother's ", "  brothers' "),
        ]
        for sing, plur in test_data:
            with self.subTest():
                out = Noun(sing).plural()
                self.assertEqual(out, plur, f"Noun({sing!r}).plural()")

            with self.subTest():
                out = Noun(plur).plural()
                self.assertEqual(out, plur, f"Noun({plur!r}).plural()")

            with self.subTest():
                out = Noun(sing).singular()
                self.assertEqual(out, sing, f"Noun({sing!r}).singular()")

            with self.subTest():
                out = Noun(plur).singular()
                self.assertEqual(out, sing, f"Noun({plur!r}).singular()")
Пример #2
0
    def test_is_singular_not_plural(self):
        test_data = [
            # "son of a guns",
            "son of a gun",
            "knight-errant",
            "about book",
            "under blanket",
            # "book under blankets",
            # "carpet below feet",
        ]

        # TODO:
        # - Words known to be singular through the pattern (e.g. son of a ...) can still be
        #   considered plural if the ... ends with s.
        # - ".*feet" matches even "carpet under feet". This is not a problem for is_singular,
        #   where the True is already taken, and returned. But, is_plural will take False from
        #   (...) below (...) because the first word is singular, and *then* it reaches the
        #   ".*feet" rule, making it True.

        for sing in test_data:
            with self.subTest():
                self.assertTrue(
                    Noun(sing).is_singular(),
                    f"Noun({sing!r}).is_singular() => True")
                self.assertFalse(
                    Noun(sing).is_plural(),
                    f"Noun({sing!r}).is_plural() => False")
Пример #3
0
 def test_singular_wrong_person(self):
     with self.assertRaises(ValueError):
         Noun("brother").singular(5)
     with self.assertRaises(ValueError):
         Noun("brother").singular("hello")
     with self.assertRaises(ValueError):
         Noun("brother").singular("first")
Пример #4
0
 def test_plural_wrong_person(self):
     with self.assertRaises(ValueError):
         Noun("brother").plural(5)
     with self.assertRaises(ValueError):
         Noun("brother").plural("hello")
     with self.assertRaises(ValueError):
         Noun("brother").plural("first")
Пример #5
0
 def test_classical_classical(self):
     classical_one = Noun("brother").classical()
     classical_two = classical_one.classical()
     self.assertEqual(
         classical_one,
         classical_two,
         "Noun(...).classical() == Noun(...).classical().classical()",
     )
Пример #6
0
 def test_as_regex(self):
     noun = Noun("brother")
     pattern = noun.as_regex()
     self.assertEqual(
         pattern,
         re.compile("brothers|brother|brethren", re.IGNORECASE),
         "Check whether as_regex produces a compiled regex object correctly.",
     )
Пример #7
0
 def test_indefinite_plural(self):
     test_data = [
         ("universe", "universes"),
         ("uniplex", "uniplexes"),
         ("height", "heights"),
         ("FSM", "FSMs"),
         ("use", "uses"),
         ("lady in waiting", "ladies in waiting"),
         ("octavo", "octavos"),
         ("D", "Ds"),
         ("Q", "Qs"),
         ("PET", "PETs"),
         ("P", "Ps"),
         ("erratum", "errata"),
         ("once-and-future-king", "once-and-future-kings"),
         ("Tth", "Tths"),
         ("urn", "urns"),
         ("DNR", "DNRs"),
         ("N", "Ns"),
         ("FACT", "FACTs"),
         ("UNESCO representative", "UNESCO representatives"),
         ("Oth", "Oths"),
     ]
     for sing, plur in test_data:
         with self.subTest():
             digit = random.randrange(2, 10)  # nosec
             out = Noun(sing).indefinite(count=digit)
             self.assertEqual(out, f"{digit} {plur}",
                              f"Noun({sing!r}).indefinite(count={digit})")
Пример #8
0
 def test_prepend_indefinite_article(self):
     for test_case in self.test_args:
         with self.subTest():
             # Expand test_case with default cases, if optional keys are not provided
             test_case = {**test_case, **{
                 "desc": f"indefinite({repr(test_case['in'])}) => {repr(test_case['out'])}",
                 "kwargs": {}
             }}
             self.assertEqual(Noun(test_case["in"]).indefinite(**test_case["kwargs"]), test_case["out"], test_case["desc"])
Пример #9
0
    def test_is_plural_not_singular(self):
        test_data = [
            "sons of gun",
            "sons of guns",
            "knights-errant",
            "about books",
            "under blankets",
            "books under blanket",
            "papers on table",
        ]

        for sing in test_data:
            with self.subTest():
                self.assertTrue(
                    Noun(sing).is_plural(),
                    f"Noun({sing!r}).is_plural() => True")
                self.assertFalse(
                    Noun(sing).is_singular(),
                    f"Noun({sing!r}).is_singular() => False")
Пример #10
0
 def test_classical_repr(self):
     noun = Noun("brother")
     classical = noun.classical()
     self.assertEqual(f"{classical!r}", "Noun('brother').classical()")
Пример #11
0
 def test_repr(self):
     noun = Noun("brother")
     self.assertEqual(f"{noun!r}", "Noun('brother')")
Пример #12
0
 def test_classical_modern(self):
     noun = Noun("brother")
     classical = noun.classical()
     modern = classical.modern()
     self.assertEqual(noun, modern,
                      "Noun(...) = Noun(...).classical().modern()")
Пример #13
0
 def test_classical_cache(self):
     noun = Noun("brother")
     classical_one = noun.classical()
     classical_two = noun.classical()
     self.assertEqual(classical_one, classical_two,
                      "Cache of Noun(...).classical()")
Пример #14
0
 def test_empty(self):
     noun = Noun("")
     noun.is_singular()
     noun.is_plural()
     noun.classical().is_plural()
     noun.singular()
     noun.plural()
     noun.classical().plural()
Пример #15
0
 def test_is_noun(self):
     noun = Noun("book")
     self.assertFalse(noun.is_verb())
     self.assertTrue(noun.is_noun())
     self.assertFalse(noun.is_adj())