How to use test_any_of method in pyshould

Best Python code snippet using pyshould_python

parser.py

Source:parser.py Github

copy

Full Screen

...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()...

Full Screen

Full Screen

test_helper_func.py

Source:test_helper_func.py Github

copy

Full Screen

...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()...

Full Screen

Full Screen

test_pipelines.py

Source:test_pipelines.py Github

copy

Full Screen

...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))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyshould automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful