Best Python code snippet using Contexts
test_pure_utils.py
Source:test_pure_utils.py  
...116            ),117        )118    def test_pluralises(self) -> None:119        """Tests that pluralises pluralises"""120        self.assertEqual(pluralise(""), "")121        self.assertEqual(pluralise("goose"), "geese")122        self.assertEqual(pluralise("dolly"), "dollies")123        self.assertEqual(pluralise("genius"), "genii")124        self.assertEqual(pluralise("pass"), "passes")125        self.assertEqual(pluralise("zero"), "zeros")126        self.assertEqual(pluralise("casino"), "casinos")127        self.assertEqual(pluralise("hero"), "heroes")128        self.assertEqual(pluralise("church"), "churches")129        self.assertEqual(pluralise("x"), "xs")130        self.assertEqual(pluralise("ant"), "ants")131        self.assertEqual(pluralise("car"), "cars")132        self.assertEqual(pluralise("wish"), "wishes")133        self.assertEqual(pluralise("morphosis"), "morphosises")134        self.assertEqual(pluralise("s"), "ss")135    def test_sanitise(self) -> None:136        """Tests sanity"""137        self.assertEqual(sanitise("class"), "class_")138    def test_set_attr(self) -> None:139        """Tests `set_attr`"""140        class Att(object):141            """Mock class for `test_set_attr`"""142        self.assertEqual(set_attr(Att, "bar", 5).bar, 5)143    def test_set_item(self) -> None:144        """Tests `set_item`"""145        self.assertEqual(set_item({}, "foo", "haz")["foo"], "haz")146    def test_strip_split(self) -> None:147        """Tests that strip_split works on separated input and separator free input"""148        self.assertTupleEqual(tuple(strip_split("foo.bar", ".")), ("foo", "bar"))...textsupport.py
Source:textsupport.py  
...57        parts.append(number_to_words(remainder))58    if remainder < 100:59        return " and ".join(parts)60    return ", ".join(parts)            61def pluralise(noun):62    plural = {63        "bison": "bison",64        "goose": "geese",  # Irregular nouns65        "moose": "moose",66        "mouse": "mice",67        "ox":    "oxen",68        "sheep": "sheep",69        "foot":  "feet",70        "tooth": "teeth",71        "man":   "men",72        "woman": "women",73        "child": "children",74    }.get(noun, None)75    if plural is not None:76        return plural77    sEnding = noun[-2:]78    pEnding = {79        "ss": "sses",   # moss     -> mosses80        "zz": "zzes",   # ?81        "sh": "shes",   # bush     -> bushes82        "ch": "ches",   # branch   -> branches83        "fe": "ves",    # knife    -> knives84        "ff": "ffs",    # cliff    -> cliffs85        "ay": "ays",    # <vowel>y -> <vowel>ys86        "ey": "eys",    #87        "iy": "iys",    #88        "oy": "oys",    #89        "uy": "uys",    #90    }.get(sEnding, None)91    if pEnding is not None:92        return noun[:-2] + pEnding93    sEnding = noun[-1]94    pEnding = {95        "y": "ies",     # family   -> families96        "f": "ves",     # loaf     -> loaves97    }.get(sEnding, None)98    if pEnding is not None:99        return noun[:-1] + pEnding100    pEnding = {101        "s": "",        # pants    -> pants102        "x": "es",      # fox      -> foxes103    }.get(sEnding, None)104    if pEnding is not None:105        return noun + pEnding106    # Fallback case.107    return noun +"s"108pluralize = pluralise   # American <- English109if __name__ == "__main__":    110    import unittest111    class NumberWordificationTests(unittest.TestCase):112        def testLessThanOneHundred(self):113            self.failUnlessEqual(number_to_words(0), "none")114            self.failUnlessEqual(number_to_words(1), "one")115            self.failUnlessEqual(number_to_words(5), "five")116            self.failUnlessEqual(number_to_words(10), "ten")117            self.failUnlessEqual(number_to_words(15), "fifteen")118            self.failUnlessEqual(number_to_words(20), "twenty")119            self.failUnlessEqual(number_to_words(21), "twenty one")120            self.failUnlessEqual(number_to_words(50), "fifty")121        def testHundreds(self):122            self.failUnlessEqual(number_to_words(100), "one hundred")123            self.failUnlessEqual(number_to_words(101), "one hundred and one")124            self.failUnlessEqual(number_to_words(111), "one hundred and eleven")125            self.failUnlessEqual(number_to_words(199), "one hundred and ninety nine")126            self.failUnlessEqual(number_to_words(999), "nine hundred and ninety nine")127        def testThousands(self):128            self.failUnlessEqual(number_to_words(1000), "one thousand")129            self.failUnlessEqual(number_to_words(1001), "one thousand and one")130            self.failUnlessEqual(number_to_words(1099), "one thousand and ninety nine")131            self.failUnlessEqual(number_to_words(1100), "one thousand, one hundred")132            self.failUnlessEqual(number_to_words(1101), "one thousand, one hundred and one")133            self.failUnlessEqual(number_to_words(11101), "eleven thousand, one hundred and one")134            self.failUnlessEqual(number_to_words(100101), "one hundred thousand, one hundred and one")135            self.failUnlessEqual(number_to_words(101101), "one hundred and one thousand, one hundred and one")136            137        def testMillions(self):138            self.failUnlessEqual(number_to_words(1000000), "one million")139            self.failUnlessEqual(number_to_words(1000001), "one million and one")140            self.failUnlessEqual(number_to_words(1900000), "one million, nine hundred thousand")141            self.failUnlessEqual(number_to_words(1900001), "one million, nine hundred thousand and one")142    class PluralisationTests(unittest.TestCase):143        def testSelectionOfCases(self):144            # One of the irregular nouns.    145            self.failUnlessEqual(pluralise("man"), "men")146            # Something other cases.147            self.failUnlessEqual(pluralise("moss"), "mosses")148            self.failUnlessEqual(pluralise("cliff"), "cliffs")    149            self.failUnlessEqual(pluralise("knife"), "knives")150            self.failUnlessEqual(pluralise("boy"), "boys")151            self.failUnlessEqual(pluralise("grey"), "greys")152            self.failUnlessEqual(pluralise("gray"), "grays")153            self.failUnlessEqual(pluralise("nappy"), "nappies")154            self.failUnlessEqual(pluralise("pants"), "pants")155            self.failUnlessEqual(pluralise("fox"), "foxes")156            # The fallback case.157            self.failUnlessEqual(pluralise("chest"), "chests")...test_digest.py
Source:test_digest.py  
...99        ({1: "test", 2: "|\ntest\n"}, {1: "test", 2: "test"}),100    ]101    for i, o in tests:102        assert p(i) == o103def test_pluralise():104    """Test the pluralisation string replacement algorithm."""105    assert pluralise("plural(0|s|m)") == "m"106    assert pluralise("plural(1|s|m)") == "s"107    assert pluralise("plural(2|s|m)") == "m"108    assert pluralise("plural(X|s|m)") == "m"109    assert pluralise("aaaaaplural(1|s|m)aaaaa") == "aaaaasaaaaa"110    assert pluralise("plural(X|s|m)plural(1|y god|olasses)") == "my god"111def test_fake_digest(fake_user: CachedUserConfig, fake_posts: NewPostsInfo):112    """Construct a digest from fake data and compare it to the expected113    output."""114    digester = Digester(str(Path.cwd() / "notifier" / "lang.toml"))115    lexicon = digester.make_lexicon(fake_user["language"])116    digest = "\n".join(make_wikis_digest(fake_posts, lexicon))117    print(digest)118    print(digest[:25].replace("\n", "\\n"))119    # Would be prohibitively difficult to test an exact match for the120    # digest - manual inspection should be sufficient. But I can check that121    # it does produce something and that it has the expected number of122    # notifications:123    assert digest.startswith("++ My Wiki\n\n+++ Other\n\n14")124    assert digest.count(lexicon["thread_opener"]) == 2...nextevent.py
Source:nextevent.py  
...57  date = dt.strftime('%A %%s %B') % date_suffix(dt.day)58  if dt.year != datetime.now().date().year:59    date += ' %s' % dt.year60  return date61def pluralise(fmt, n):62  return fmt % (n, int(n) != 1 and 's' or '')63def untilmsg(next):64  until = next - datetime.now()65  hours, seconds = divmod(until.seconds, 3600)66  days = until.days67  if days == 0:68    if hours == 0:69      return pluralise('Only %d minute%s', seconds / 60)70    return pluralise('Only %d hour%s', hours)71  return '%s, %s' % (pluralise('%d day%s', days), pluralise('%d hour%s', hours))72def printmsg(name, what, next):73  '''74  Format friendly message of when the next event is.75  NB No account is taken of timezones.76  '''77  print ('%s: %s (%s until %s!)' % (78    name,79    date_nice(next),80    untilmsg(next),81    what,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
