Best Python code snippet using pyshould_python
parser.py
Source: parser.py
...32 if first_char not in symbols:33 return self.ERROR, "expected any of '" + symbols + "', got " + first_char, input_str34 return self.OK, first_char, input_str[1:]35 return inner36def test_any_of():37 symbols = ""38 p = Parser(any_of(symbols))39 tag, p_res, leftover = p("")40 assert tag == Parser.ERROR41 assert p_res == Parser.eof42 assert leftover == ""43 44 symbols = "abc"45 p = Parser(any_of(symbols))46 tag, p_res, leftover = p("ai")47 assert tag == Parser.OK48 assert p_res == "a"49 assert leftover == "i"50 tag, p_res, leftover = p("ia")51 assert tag == Parser.ERROR52 assert leftover == "ia"53 54def chain(*parsers):55 """56 : param parsers: list of Parser instances to be combined57 : return: superposition of parsers58 """59 def shallow_parse(self, input_str):60 return self.OK, "", input_str61 62 def inner(self, input_str):63 tag, res, leftover = shallow_parse(self, input_str)64 res_list = []65 for parser in parsers:66 tag, res, leftover = parser(leftover)67 res_list.append(res)68 if tag != Parser.OK:69 return tag, res_list, leftover70 return self.OK, res_list, leftover71 return inner72def test_chain():73 input_str = "()."74 p = Parser(chain())75 tag, res, leftover = p(input_str)76 assert tag == Parser.OK77 assert len(res) == 078 assert leftover == input_str79 80 p1, p2 = Parser(any_of("(")), Parser(any_of(")"))81 p = Parser(chain(p1, p2))82 tag, res, leftover = p(input_str)83 assert tag == Parser.OK84 assert len(res) == 285 assert res[0] == input_str[0]86 assert res[1] == input_str[1]87 assert leftover == input_str[2:]88def choice(*parsers):89 """90 : param parsers: list of Parser instances, each is applied to input string independently91 : return: result of first parser in 'parsers' that returns OK as a tag, else informs user about failure of all92 """93 choice.err_no_match = "none matched"94 95 def inner(self, input_str):96 for parser in parsers:97 tag, res, leftover = parser(input_str)98 if tag == Parser.OK:99 return tag, res, leftover100 return self.ERROR, choice.err_no_match, input_str101 return inner102 103def test_choice():104 p = Parser(choice(Parser(any_of(".")), Parser(any_of("!"))))105 for symbol in ".!?":106 tag, res, leftover = p(symbol)107 if symbol in ".!":108 assert tag == Parser.OK109 assert res == symbol110 assert leftover == ""111 else:112 assert tag == Parser.ERROR113 assert res == choice.err_no_match114 assert leftover == symbol115def many(parser, empty=True):116 """117 : param parser: a Parser instance which is to be applied to input string repeatedly until it returns ERROR118 : return: result - list of 'parser' results119 """120 def inner(self, input_str):121 res_list = []122 tag, res, leftover = parser(input_str)123 while tag == Parser.OK:124 res_list.append(res)125 tag, res, leftover = parser(leftover)126 if empty:127 return Parser.OK, res_list, leftover128 return Parser.ERROR, res, input_str # if 'empty'==false, returns error message returned by 'parser'129 return inner130def test_many():131 p = Parser(many(Parser(any_of("bcehiktrqu "))))132 input_str = "the quick red fox jumps over the lazy brown dog"133 tag, res, leftover = p(input_str)134 assert tag == Parser.OK135 assert len(res) == 12136 assert leftover == input_str[12:] 137if __name__ == "__main__":138 test_any_of()139 test_chain()140 test_choice()141 test_many()...
test_helper_func.py
Source: test_helper_func.py
...4 assert(line_to_string(l) == "XXX")5def even(x):6 '''Liefert True, falls x eine gerade Zahl ist.'''7 return x % 2 == 08def test_any_of():9 a1 = [1,3,5,7,9]10 a2 = [1,2,3,4,5]11 assert(any_of(a1,even) == False)12 assert(any_of(a2,even) == True)13def test_board_to_string():14 b = [["1","2","3"],["4","5","6"],["7","8","9"]]15 assert(board_to_string(b) == "1 | 2 | 3\n--+---+--\n4 | 5 | 6\n--+---+--\n7 | 8 | 9")16def test_helper_functions():17 test_line_to_string()18 test_any_of()19 test_board_to_string()20 21if __name__ == "__main__":22 test_helper_functions()...
test_pipelines.py
Source: test_pipelines.py
...4 v = module.AllOf(module.Int(min=0), module.Int(max=10))5 assert benchmark(v, 1) == 16# =============================================================================7@pytest.mark.benchmark(group="OneOf")8def test_any_of(module, benchmark):9 v = module.OneOf(module.Int(min=0), module.Int(min=10))...
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.
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!!