Best Python code snippet using behave
test_plurals.py
Source:test_plurals.py
...6 1: u'One apple',7 3: u'Few apples',8 'other': u'{count} apples',9 }10 assert pluralize(d, 0) == u'No apples'11 assert pluralize(d, 1) == u'One apple'12 assert pluralize(d, 3) == u'Few apples'13 assert pluralize(d, 10) == u'{count} apples'14def test_pluralize_literal():15 d = {16 'zero': u'No apples',17 'one': u'One apple',18 'few': u'Few apples',19 'many': u'{count} apples',20 }21 assert pluralize(d, 0) == u'No apples'22 assert pluralize(d, 1) == u'One apple'23 assert pluralize(d, 3) == u'{count} apples'24 assert pluralize(d, 10) == u'{count} apples'25def test_pluralize_mixed():26 d = {27 'one': u'One apple',28 2: u'Two apples',29 'other': u'{count} apples',30 }31 assert pluralize(d, 1) == u'One apple'32 assert pluralize(d, 2) == u'Two apples'33 assert pluralize(d, 10) == u'{count} apples'34def test_pluralize_zero_or_many():35 d = {36 'zero': u'off',37 'many': u'on'38 }39 assert pluralize(d, 3) == u'on'40 d = {41 'zero': u'off',42 'many': u'on'43 }44 assert pluralize(d, 0) == u'off'45 assert pluralize(d, None) == u'off'46 assert pluralize({}, 3) == u''47def test_pluralize_other():48 d = {49 'one': u'One apple',50 'other': u'meh',51 }52 assert pluralize(d, 0) == u'meh'53 assert pluralize(d, 1) == u'One apple'54 assert pluralize(d, 2) == u'meh'55 assert pluralize(d, 3) == u'meh'56 assert pluralize(d, 10) == u'meh'57def test_two_plural_mode():58 d = {59 'zero': u'zero',60 'one': u'one',61 'two': u'two',62 'few': u'few',63 'other': u'other',64 }65 locale = Locale('en')66 assert pluralize(d, 0, locale) == u'zero'67 assert pluralize(d, 1, locale) == u'one'68 assert pluralize(d, 2, locale) == u'other'69 assert pluralize(d, 3, locale) == u'other'70 assert pluralize(d, 4, locale) == u'other'71 assert pluralize(d, 5, locale) == u'other'72 assert pluralize(d, 6, locale) == u'other'73 assert pluralize(d, 7, locale) == u'other'74 assert pluralize(d, 10, locale) == u'other'75 assert pluralize(d, 11, locale) == u'other'76 assert pluralize(d, 50, locale) == u'other'77 assert pluralize(d, 99, locale) == u'other'78 assert pluralize(d, 101, locale) == u'other'79 assert pluralize(d, 102, locale) == u'other'80 assert pluralize(d, 105, locale) == u'other'81def test_one_plural_mode():82 d = {83 'one': u'one',84 'two': u'two',85 'few': u'few',86 'many': u'many',87 'other': u'other',88 }89 locale = Locale('zh')90 assert pluralize(d, 0, locale) == u'other'91 assert pluralize(d, 1, locale) == u'other'92 assert pluralize(d, 2, locale) == u'other'93 assert pluralize(d, 3, locale) == u'other'94 assert pluralize(d, 4, locale) == u'other'95 assert pluralize(d, 5, locale) == u'other'96 assert pluralize(d, 6, locale) == u'other'97 assert pluralize(d, 7, locale) == u'other'98 assert pluralize(d, 10, locale) == u'other'99 assert pluralize(d, 11, locale) == u'other'100 assert pluralize(d, 50, locale) == u'other'101 assert pluralize(d, 99, locale) == u'other'102 assert pluralize(d, 101, locale) == u'other'103 assert pluralize(d, 102, locale) == u'other'104 assert pluralize(d, 105, locale) == u'other'105 d = {106 'zero': u'zero',107 'one': u'one',108 'two': u'two',109 'few': u'few',110 'many': u'many',111 'other': u'other',112 }113 locale = Locale('zh')114 assert pluralize(d, 0, locale) == u'zero'115def test_pluralize_arabic():116 d = {117 'zero': u'zero',118 'one': u'one',119 'two': u'two',120 'few': u'few',121 'many': u'many',122 'other': u'other',123 }124 locale = Locale('ar')125 assert pluralize(d, 0, locale) == u'zero'126 assert pluralize(d, 1, locale) == u'one'127 assert pluralize(d, 2, locale) == u'two'128 assert pluralize(d, 3, locale) == u'few'129 assert pluralize(d, 4, locale) == u'few'130 assert pluralize(d, 5, locale) == u'few'131 assert pluralize(d, 6, locale) == u'few'132 assert pluralize(d, 7, locale) == u'few'133 assert pluralize(d, 10, locale) == u'few'134 assert pluralize(d, 11, locale) == u'many'135 assert pluralize(d, 50, locale) == u'many'136 assert pluralize(d, 99, locale) == u'many'137 assert pluralize(d, 101, locale) == u'other'138 assert pluralize(d, 102, locale) == u'other'139 assert pluralize(d, 105, locale) == u'few'140def test_pluralize_russian():141 d = {142 'zero': u'zero',143 'one': u'one',144 'two': u'two',145 'few': u'few',146 'many': u'many',147 'other': u'other',148 }149 locale = Locale('ru')150 assert pluralize(d, 0, locale) == u'zero'151 assert pluralize(d, 1, locale) == u'one'152 assert pluralize(d, 2, locale) == u'few'153 assert pluralize(d, 3, locale) == u'few'154 assert pluralize(d, 4, locale) == u'few'155 assert pluralize(d, 5, locale) == u'many'156 assert pluralize(d, 6, locale) == u'many'157 assert pluralize(d, 7, locale) == u'many'158 assert pluralize(d, 10, locale) == u'many'159 assert pluralize(d, 11, locale) == u'many'160 assert pluralize(d, 21, locale) == u'one'161 assert pluralize(d, 22, locale) == u'few'162 assert pluralize(d, 23, locale) == u'few'163 assert pluralize(d, 24, locale) == u'few'164 assert pluralize(d, 25, locale) == u'many'165 assert pluralize(d, 50, locale) == u'many'166 assert pluralize(d, 99, locale) == u'many'167 assert pluralize(d, 101, locale) == u'one'168 assert pluralize(d, 102, locale) == u'few'169 assert pluralize(d, 105, locale) == u'many'170 assert pluralize(d, 111, locale) == u'many'171 assert pluralize(d, 112, locale) == u'many'172 assert pluralize(d, 113, locale) == u'many'173 assert pluralize(d, 114, locale) == u'many'174 assert pluralize(d, 119, locale) == u'many'175 assert pluralize(d, 121, locale) == u'one'176 assert pluralize(d, 122, locale) == u'few'...
tests.py
Source:tests.py
...3from lambda_utils import BadRequest4from pluralizer import pluralize, maybe_pluralize, pluralize_handler5class TestPluralizer(unittest.TestCase):6 """Test the functionality of the `pluralizer` file."""7 def test_pluralize(self):8 """9 The `pluralize` function should return the plural form of any noun.10 """11 plural_mapping = {12 "marker": "markers",13 "tree": "trees",14 "story": "stories",15 "porcupine": "porcupines",16 "kiss": "kisses",17 "hero": "heroes",18 "day": "days",19 "monkey": "monkeys"20 }21 for singular, plural in plural_mapping.items():22 self.assertEqual(plural, pluralize(singular))23 def test_maybe_pluralize_one(self):24 """25 `pluralize` should not be called if `quantity` is 1.26 """27 unpluralized = maybe_pluralize("tree", 1)28 self.assertEqual(unpluralized, "tree")29 @patch("pluralizer.pluralize")30 def test_maybe_pluralize_many(self, pluralize_):31 """32 `pluralize` should be called in all other cases.33 """34 expected = pluralize_.return_value = "pluralize's return value"35 return_value = maybe_pluralize("tree", 2)36 self.assertEqual(return_value, expected)37 pluralize_.assert_called_once_with("tree")38 def test_pluralize_handler_no_noun(self):39 event = {"quantity": 10}40 self.assertRaises(41 BadRequest,42 lambda: pluralize_handler(event, None)43 )44 @patch("pluralizer.maybe_pluralize")45 def test_pluralize_handler_correct(self, maybe_pluralize):46 """47 When pluralize_handler is called correctly, check it delegates to48 maybe_pluralize and wraps the result in a dict accordingly.49 """...
test_pluralize.py
Source:test_pluralize.py
2from django.template.defaultfilters import pluralize3from django.test import SimpleTestCase4class FunctionTests(SimpleTestCase):5 def test_integers(self):6 self.assertEqual(pluralize(1), '')7 self.assertEqual(pluralize(0), 's')8 self.assertEqual(pluralize(2), 's')9 def test_floats(self):10 self.assertEqual(pluralize(0.5), 's')11 self.assertEqual(pluralize(1.5), 's')12 def test_decimals(self):13 self.assertEqual(pluralize(Decimal(1)), '')14 self.assertEqual(pluralize(Decimal(0)), 's')15 self.assertEqual(pluralize(Decimal(2)), 's')16 def test_lists(self):17 self.assertEqual(pluralize([1]), '')18 self.assertEqual(pluralize([]), 's')19 self.assertEqual(pluralize([1, 2, 3]), 's')20 def test_suffixes(self):21 self.assertEqual(pluralize(1, 'es'), '')22 self.assertEqual(pluralize(0, 'es'), 'es')23 self.assertEqual(pluralize(2, 'es'), 'es')24 self.assertEqual(pluralize(1, 'y,ies'), 'y')25 self.assertEqual(pluralize(0, 'y,ies'), 'ies')26 self.assertEqual(pluralize(2, 'y,ies'), 'ies')27 self.assertEqual(pluralize(0, 'y,ies,error'), '')28 def test_no_len_type(self):29 self.assertEqual(pluralize(object(), 'y,es'), 'y')30 self.assertEqual(pluralize(object(), 'es'), '')31 def test_value_error(self):...
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!!