Best Python code snippet using molecule_python
boolext.py
Source:boolext.py
...7 w_lower = w.lower()8 w_upper = w.upper()9 with self.subTest(w_lower=w_lower, w_upper=w_upper, w=w):10 if CASE_INSENSITIVE:11 self.assertEqual(StrBoolResult.TRUE, to_bool(w))12 self.assertEqual(StrBoolResult.TRUE, to_bool(w_lower))13 self.assertEqual(StrBoolResult.TRUE, to_bool(w_upper))14 else:15 self.assertEqual(StrBoolResult.TRUE, to_bool(w))16 if w == w_lower:17 self.assertEqual(StrBoolResult.TRUE, to_bool(w_lower))18 else:19 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_lower))20 if w == w_upper:21 self.assertEqual(StrBoolResult.TRUE, to_bool(w_upper))22 else:23 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_upper))24 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w))25 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w))26 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_lower))27 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_lower))28 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_upper))29 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_upper))30 def test_false(self):31 for w in WORD_FALSE:32 w_lower = w.lower()33 w_upper = w.upper()34 with self.subTest(w_lower=w_lower, w_upper=w_upper, w=w):35 if CASE_INSENSITIVE:36 self.assertEqual(StrBoolResult.FALSE, to_bool(w))37 self.assertEqual(StrBoolResult.FALSE, to_bool(w_lower))38 self.assertEqual(StrBoolResult.FALSE, to_bool(w_upper))39 else:40 self.assertEqual(StrBoolResult.FALSE, to_bool(w))41 if w == w_lower:42 self.assertEqual(StrBoolResult.FALSE, to_bool(w_lower))43 else:44 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_lower))45 if w == w_upper:46 self.assertEqual(StrBoolResult.FALSE, to_bool(w_upper))47 else:48 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_upper))49 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w))50 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w))51 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_lower))52 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_lower))53 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_upper))54 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_upper))55 def test_unknown(self):56 unknown_words = ("A", "B", "C")57 for w in unknown_words:58 self.assertFalse(w in WORD_TRUE, f"`{w}` exists in `WORD_TRUE`")59 self.assertFalse(w in WORD_FALSE, f"`{w}` exists in `WORD_FALSE`")60 w_lower = w.lower()61 w_upper = w.upper()62 with self.subTest(w_lower=w_lower, w_upper=w_upper, w=w):63 if CASE_INSENSITIVE:64 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w))65 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w_lower))66 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w_upper))67 else:68 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w))69 if w == w_lower:70 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w_lower))71 else:72 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_lower))73 if w == w_upper:74 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(w_upper))75 else:76 self.assertNotEqual(StrBoolResult.UNKNOWN, to_bool(w_upper))77 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w))78 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w))79 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_lower))80 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_lower))81 self.assertNotEqual(StrBoolResult.TRUE, to_bool(w_upper))82 self.assertNotEqual(StrBoolResult.FALSE, to_bool(w_upper))83 def test_cast_non_str(self):84 self.assertEqual(StrBoolResult.UNKNOWN, to_bool(object()))85 def test_cast_bool(self):86 self.assertEqual(StrBoolResult.TRUE, to_bool(True))87 self.assertEqual(StrBoolResult.FALSE, to_bool(False))88 def test_str_bool_result(self):89 self.assertEqual(True, StrBoolResult.TRUE.to_bool())90 self.assertNotEqual(False, StrBoolResult.TRUE.to_bool())91 self.assertEqual(False, StrBoolResult.FALSE.to_bool())92 self.assertNotEqual(True, StrBoolResult.FALSE.to_bool())93 with self.assertRaises(ValueError):...
peephole.py
Source:peephole.py
1"""Peephole evaluator optimiser."""2from routemaster.exit_conditions.operations import Operation3MATCHERS = [4 (5 [6 (Operation.NOT,),7 (Operation.NOT,),8 ],9 [10 ],11 ),12 (13 [14 (Operation.TO_BOOL,),15 (Operation.TO_BOOL,),16 ],17 [18 (Operation.TO_BOOL,),19 ],20 ),21 (22 [23 (Operation.NOT,),24 (Operation.TO_BOOL,),25 ],26 [27 (Operation.NOT,),28 ],29 ),30 (31 [32 (Operation.AND,),33 (Operation.TO_BOOL,),34 ],35 [36 (Operation.AND,),37 ],38 ),39 (40 [41 (Operation.OR,),42 (Operation.TO_BOOL,),43 ],44 [45 (Operation.OR,),46 ],47 ),48 (49 [50 (Operation.EQ,),51 (Operation.TO_BOOL,),52 ],53 [54 (Operation.EQ,),55 ],56 ),57 (58 [59 (Operation.LT,),60 (Operation.TO_BOOL,),61 ],62 [63 (Operation.LT,),64 ],65 ),66 (67 [68 (Operation.GT,),69 (Operation.TO_BOOL,),70 ],71 [72 (Operation.GT,),73 ],74 ),75]76def peephole_optimise(instructions):77 """Run peephole optimisations over a given instruction sequence."""78 instructions = list(instructions)79 any_changes = True80 while any_changes:81 any_changes = False82 for match_pattern, replace_pattern in MATCHERS:83 match_pattern_length = len(match_pattern)84 for index in range(len(instructions) + 1 - match_pattern_length):85 if (86 instructions[index:index + match_pattern_length] ==87 match_pattern88 ):89 instructions[index:index + match_pattern_length] = \90 replace_pattern91 any_changes = True92 break93 # TO_BOOL after property elimination94 for index in range(len(instructions) - 1):95 if (96 instructions[index][0] == Operation.PROPERTY and97 instructions[index + 1][0] == Operation.TO_BOOL98 ):99 del instructions[index + 1]100 any_changes = True101 break...
utils_test.py
Source:utils_test.py
...14 number = utils.number_format(1000)15 self.assertEqual(number, '1,000')16 number = utils.number_format(1234567890)17 self.assertEqual(number, '1,234,567,890')18 def test_str_to_bool(self):19 self.assertTrue(utils.to_bool('y'))20 self.assertTrue(utils.to_bool('YES'))21 self.assertTrue(utils.to_bool('true'))22 self.assertTrue(utils.to_bool('TRUE'))23 self.assertTrue(utils.to_bool('Y'))24 self.assertFalse(utils.to_bool('rodger'))25 self.assertFalse(utils.to_bool('False'))26 self.assertFalse(utils.to_bool('FaLse'))27 self.assertFalse(utils.to_bool('no'))28 self.assertFalse(utils.to_bool('n'))29class TestStatsd(unittest.TestCase):30 def test_parse_url(self):31 self.assertEqual(32 ('example.com', 9999, 'prefix'),33 metrics.parse_url('udp://example.com:9999/prefix'))34 def test_parse_url_defaults(self):35 self.assertEqual(36 ('localhost', 8125, 'sixpack'),...
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!!