How to use init_parser method in autotest

Best Python code snippet using autotest_python

test_parser.py

Source:test_parser.py Github

copy

Full Screen

...15 input_str = """16 //comment17 """18 list_of_expected = [SingleLineComment]19 parser = init_parser(input_str)20 program = parser.parse_program()21 self.assert_instructions(program, list_of_expected)22 def test_multi_comment(self):23 input_str = """/*24 ....25 komentarz26 ....27 */"""28 list_of_expected = [MultiLineComment]29 parser = init_parser(input_str)30 program = parser.parse_program()31 self.assert_instructions(program, list_of_expected)32 def test_int_variable_declaration_without_init(self):33 input_str = """34 int i;35 """36 list_of_expected = [VariableDeclaration]37 parser = init_parser(input_str)38 program = parser.parse_program()39 self.assert_instructions(program, list_of_expected)40 def test_type_in_int_variable_declaration(self):41 input_str = """42 int i;43 """44 parser = init_parser(input_str)45 program = parser.parse_program()46 var_type = program[0].type47 self.assertTrue(isinstance(var_type, Type))48 def test_type_in_bool_variable_declaration(self):49 input_str = """50 bool b;51 """52 parser = init_parser(input_str)53 program = parser.parse_program()54 var_type = program[0].type55 self.assertTrue(isinstance(var_type, Type))56 def test_type_in_string_variable_declaration(self):57 input_str = """58 std::string b;59 """60 parser = init_parser(input_str)61 program = parser.parse_program()62 var_type = program[0].type63 self.assertTrue(isinstance(var_type, Type))64 def test_default_value_in_int_variable_declaration(self):65 input_str = """66 int i;67 """68 parser = init_parser(input_str)69 program = parser.parse_program()70 var_value = program[0].value.value71 self.assertEqual(var_value, 0)72 def test_default_value_in_bool_variable_declaration(self):73 input_str = """74 bool i;75 """76 parser = init_parser(input_str)77 program = parser.parse_program()78 var_value = program[0].value.value79 self.assertEqual(var_value, False)80 def test_default_value_in_string_variable_declaration(self):81 input_str = """82 std::string i;83 """84 parser = init_parser(input_str)85 program = parser.parse_program()86 var_value = program[0].value.value87 self.assertEqual(var_value, "")88 def test_int_variable_declaration_with_init(self):89 input_str = """90 int i = 11;91 """92 list_of_expected = [VariableDeclaration]93 parser = init_parser(input_str)94 program = parser.parse_program()95 self.assert_instructions(program, list_of_expected)96 def test_int_value_in_variable_declaration_with_init(self):97 input_str = """98 int i = 11;99 """100 parser = init_parser(input_str)101 program = parser.parse_program()102 literal = program[0].value103 self.assertTrue(isinstance(literal, Literal))104 literal_value = literal.value105 self.assertEqual(literal_value, 11)106 def test_bool_value_in_variable_declaration_with_init(self):107 input_str = """108 bool i = true;109 """110 parser = init_parser(input_str)111 program = parser.parse_program()112 literal = program[0].value113 self.assertTrue(isinstance(literal, Literal))114 literal_value = literal.value115 self.assertEqual(literal_value, True)116 def test_string_value_in_variable_declaration_with_init(self):117 input_str = """118 std::string i = "napis";119 """120 parser = init_parser(input_str)121 program = parser.parse_program()122 literal = program[0].value123 self.assertTrue(isinstance(literal, Literal))124 literal_value = literal.value125 self.assertEqual(literal_value, "napis")126 def test_boolean_variable_declaration_with_init(self):127 input_str = """128 bool i = true;129 """130 list_of_expected = [VariableDeclaration]131 parser = init_parser(input_str)132 program = parser.parse_program()133 self.assert_instructions(program, list_of_expected)134 def test_string_variable_declaration_with_init(self):135 input_str = """136 std::string i = "napis";137 """138 list_of_expected = [VariableDeclaration]139 parser = init_parser(input_str)140 program = parser.parse_program()141 self.assert_instructions(program, list_of_expected)142 def test_variable_assignment_with_int(self):143 input_str = """144 i = 11;145 """146 list_of_expected = [VariableAssignment]147 parser = init_parser(input_str)148 program = parser.parse_program()149 self.assert_instructions(program, list_of_expected)150 def test_variable_assignment_with_string(self):151 input_str = """152 i = "text";153 """154 list_of_expected = [VariableAssignment]155 parser = init_parser(input_str)156 program = parser.parse_program()157 self.assert_instructions(program, list_of_expected)158 def test_variable_assignment_with_boolean(self):159 input_str = """160 i = false;161 """162 list_of_expected = [VariableAssignment]163 parser = init_parser(input_str)164 program = parser.parse_program()165 self.assert_instructions(program, list_of_expected)166 def test_arithmetic_nomultiplication_nobrackets(self):167 input_str = """168 i = a+b+c;169 """170 list_of_expected = [VariableAssignment]171 parser = init_parser(input_str)172 program = parser.parse_program()173 self.assert_instructions(program, list_of_expected)174 def test_arithmetic_multiplication_nobrackets(self):175 input_str = """176 i = a+b*c;177 """178 list_of_expected = [VariableAssignment]179 parser = init_parser(input_str)180 program = parser.parse_program()181 self.assert_instructions(program, list_of_expected)182 def test_arithmetic_multiplication_brackets(self):183 input_str = """184 i = d*(a+(b*c));185 """186 list_of_expected = [VariableAssignment]187 parser = init_parser(input_str)188 program = parser.parse_program()189 self.assert_instructions(program, list_of_expected)190 def test_function_declaration_noargs_nobody(self):191 input_str = """192 int fun(){193 }194 """195 list_of_expected = [FunctionDeclaration]196 parser = init_parser(input_str)197 program = parser.parse_program()198 self.assert_instructions(program, list_of_expected)199 def test_function_declaration_args_nobody(self):200 input_str = """201 int fun(int a, int b){202 }203 """204 list_of_expected = [FunctionDeclaration]205 parser = init_parser(input_str)206 program = parser.parse_program()207 self.assert_instructions(program, list_of_expected)208 def test_function_declaration_args_body(self):209 input_str = """210 int fun(int a, int b){211 return a;212 }"""213 list_of_expected = [FunctionDeclaration]214 parser = init_parser(input_str)215 program = parser.parse_program()216 self.assert_instructions(program, list_of_expected)217 def test_function_invocation_noargs(self):218 input_str = """219 fun();220 """221 list_of_expected = [FunctionInvocation]222 parser = init_parser(input_str)223 program = parser.parse_program()224 self.assert_instructions(program, list_of_expected)225 def test_function_invocation_args(self):226 input_str = """227 fun(a, b, "essa", true);228 """229 list_of_expected = [FunctionInvocation]230 parser = init_parser(input_str)231 program = parser.parse_program()232 self.assert_instructions(program, list_of_expected)233 def test_print(self):234 input_str = """235 std::cout<<"napis"<<std::endl;236 """237 list_of_expected = [PrintStatement]238 parser = init_parser(input_str)239 program = parser.parse_program()240 self.assert_instructions(program, list_of_expected)241 def test_return_no_value(self):242 input_str = """243 return;244 """245 list_of_expected = [ReturnExpression]246 parser = init_parser(input_str)247 program = parser.parse_program()248 self.assert_instructions(program, list_of_expected)249 def test_return_value(self):250 input_str = """251 return true;252 """253 list_of_expected = [ReturnExpression]254 parser = init_parser(input_str)255 program = parser.parse_program()256 self.assert_instructions(program, list_of_expected)257 def test_while_body(self):258 input_str = """259 while(i<10){260 int i = i+1;261 }"""262 list_of_expected = [WhileStatement]263 parser = init_parser(input_str)264 program = parser.parse_program()265 self.assert_instructions(program, list_of_expected)266 def test_if_body_noelse(self):267 input_str = """268 if(true){269 std::cout<<"dziala"<<std::endl;270 }"""271 list_of_expected = [IfStatement]272 parser = init_parser(input_str)273 program = parser.parse_program()274 self.assert_instructions(program, list_of_expected)275 def test_if_body_else_body(self):276 input_str = """277 if(true){278 std::cout<<"dziala"<<std::endl;279 }else{280 std::cout<<"to tez"<<std::endl;281 }282 """283 list_of_expected = [IfStatement]284 parser = init_parser(input_str)285 program = parser.parse_program()286 self.assert_instructions(program, list_of_expected)287 def test_nested_instructions(self):288 input_str = """289 int fun(int a, int b, int c){290 return a+b+c;291 }292 int i = 1;293 while(true){294 if(i<10){295 i = i+10;296 std::string str = "napis";297 }else{298 fun(1,2,3);299 }300 }301 std::cout<<"dziala"<<std::endl;302 return 1;303 """304 parser = init_parser(input_str)305 first_level = parser.parse_program()306 first_level_expected = [FunctionDeclaration, VariableDeclaration, WhileStatement, PrintStatement,307 ReturnExpression]308 fun_decl = first_level[0].instructions309 fun_decl_expected = [ReturnExpression]310 while_stmt = first_level[2].instructions311 while_stmt_expected = [IfStatement]312 nested_if_stmt = while_stmt[0].if_instructions313 nested_if_stmt_expected = [VariableAssignment, VariableDeclaration]314 nested_else_stmt = while_stmt[0].else_instructions315 nested_else_stmt_expected = [FunctionInvocation]316 self.assert_instructions(first_level, first_level_expected)317 self.assert_instructions(fun_decl, fun_decl_expected)318 self.assert_instructions(while_stmt, while_stmt_expected)319 self.assert_instructions(nested_if_stmt, nested_if_stmt_expected)320 self.assert_instructions(nested_else_stmt, nested_else_stmt_expected)321if __name__ == '__main__':322 unittest.main()323def init_parser(test_string):324 code_provider = CodeProvider(io.StringIO(test_string))325 lexer = Lexer(code_provider)...

Full Screen

Full Screen

make_pdf.py

Source:make_pdf.py Github

copy

Full Screen

1import argparse2import fnmatch3import os4from notebook_as_pdf import PDFExporter,notebook_to_pdf5import nbformat6import shutil7import PyPDF28import pathlib9def parse_args():10 print('parse_args...')11 parser = argparse.ArgumentParser()12 commands = parser.add_subparsers(dest='command')13 commands.required = True14 init_parser = commands.add_parser('dir')15 init_parser.set_defaults(func=convert_dir)16 init_parser.add_argument('--path', '-p')17 init_parser.add_argument('--out', '-o', default='.')18 init_parser.add_argument('--recursive', '-r', action="store_true", default=True)19 init_parser.add_argument('--include', '-i', default='')20 init_parser.add_argument('--exclude', '-e', default='')21 init_parser.add_argument('--config', '-c', default='')22 init_parser.add_argument('--clean_output', action="store_true", default=False)23 24 return parser.parse_args()25def get_file_first_name(file_name): 26 basename = os.path.basename(file_name)27 firstname = os.path.splitext(basename)[0]28 return firstname29def export_pdf(full, out_root_path, config):30 firstname = get_file_first_name(full)31 print(firstname)32 newname = firstname + '.pdf'33 pdfname = os.path.join(out_root_path, newname)34 exp = PDFExporter(config)35 if os.path.exists(pdfname):36 print(' skip exists:', full)37 return38 with open(full, 'rb') as f:39 nb = nbformat.reads(f.read(), as_version=4)40 ob = exp.from_notebook_node(nb)41 with open(pdfname, 'wb+') as fw:42 fw.write(ob[0])43def join_pdf(path, output_filename='all_in_one.pdf'):44 with os.scandir(path) as it:45 pdf_merge = []46 for entry in it:47 if not fnmatch.fnmatch(entry.name, "*.pdf"):48 continue49 if entry.name == output_filename:50 continue51 pdf_merge.append(os.path.join(path, entry.name))52 pdf_merge.sort()53 merger = PyPDF2.PdfFileMerger()54 for f in pdf_merge:55 firstname = get_file_first_name(f)56 merger.append(PyPDF2.PdfFileReader(f), bookmark=firstname)57 with open(os.path.join(path, output_filename), 'wb') as writer:58 merger.write(writer)59 60 return61 if len(pdf_merge) > 0:62 pdf_writer = PyPDF2.PdfFileWriter()63 for f in pdf_merge:64 with open(f, 'rb') as reader:65 pdf_reader = PyPDF2.PdfFileReader(reader)66 for pageNum in range(pdf_reader.numPages):67 pageObj = pdf_reader.getPage(pageNum)68 pdf_writer.addPage(pageObj)69 70 with open(os.path.join(path, output_filename), 'wb') as writer:71 pdf_writer.write(writer)72 73def in_filter(full, filters) -> bool:74 if fnmatch.fnmatch(full, filters):75 return True76 return False77def working_tree(path, recursive, include, exclude, tree):78 with os.scandir(path) as it:79 for entry in it:80 full = os.path.join(path, entry.name)81 if entry.is_file (follow_symlinks=False):82 if include != '' and not in_filter(entry.name, include):83 continue84 if exclude != '' and in_filter(entry.name, exclude):85 continue86 tree.append(full)87 elif entry.is_dir (follow_symlinks=False) and recursive:88 if exclude != '' and in_filter(entry.name, exclude):89 continue90 working_tree(full, recursive, include, exclude, tree)91 92def print_tree(tree):93 print('tree:')94 for full in tree:95 print(' ', full)96def convert_dir(args):97 path = args.path98 recursive = args.recursive99 #filters = set(args.filter.split(','))100 include = args.include101 exclude = args.exclude102 outpath = args.out103 clean_output = args.clean_output104 print('convert folder from ', path)105 if not os.path.exists(path):106 raise FileNotFoundError(path)107 source_files = []108 working_tree(path, recursive, include, exclude, source_files)109 print_tree(source_files)110 if clean_output and os.path.exists(outpath):111 shutil.rmtree(outpath)112 113 pathlib.Path(outpath).mkdir(parents=False, exist_ok=True) 114 for full in source_files:115 export_pdf(full, outpath, None)116 117 join_pdf(outpath)118def main():119 print('main...')120 args = parse_args()121 args.func(args)122#if __name__ == '__main__':...

Full Screen

Full Screen

radiant.py

Source:radiant.py Github

copy

Full Screen

...30 subparsers = parser.add_subparsers(31 title="sub-commands",32 help="Access the help page for a sub-command with: sub-command -h",33 )34 scripts.czi_to_tiff.init_parser(subparsers)35 scripts.nd2_to_tiff.init_parser(subparsers)36 scripts.select_nuclei.init_parser(subparsers)37 scripts.export_objects.init_parser(subparsers)38 scripts.measure_objects.init_parser(subparsers)39 scripts.radial_population.init_parser(subparsers)40 scripts.radial_object.init_parser(subparsers)41 scripts.radial_trajectory.init_parser(subparsers)42 scripts.radial_points.init_parser(subparsers)43 scripts.tiff_findoof.init_parser(subparsers)44 scripts.tiff_segment.init_parser(subparsers)45 scripts.tiff_desplit.init_parser(subparsers)46 scripts.tiff_split.init_parser(subparsers)47 scripts.tiffcu.init_parser(subparsers)48 scripts.pipeline.init_parser(subparsers)49 scripts.report.init_parser(subparsers)50 # argcomplete.autocomplete(parser)51 args = parser.parse_args()52 args = args.parse(args)...

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 autotest 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