How to use _do_test method in prospector

Best Python code snippet using prospector_python

test_block.py

Source:test_block.py Github

copy

Full Screen

...31 ${caller.body()}32 </%def>33 """34 )35 self._do_test(36 template, ["foo:", "this is the block x"], filters=result_lines37 )38 def test_named_block_in_call(self):39 assert_raises_message(40 exceptions.CompileException,41 "Named block 'y' not allowed inside of <%call> tag",42 Template,43 """44 <%self:foo x="5">45 <%block name="y">46 this is the block47 </%block>48 </%self:foo>49 <%def name="foo(x)">50 foo:51 ${caller.body()}52 ${caller.y()}53 </%def>54 """,55 )56 def test_name_collision_blocks_toplevel(self):57 assert_raises_message(58 exceptions.CompileException,59 "%def or %block named 'x' already exists in this template",60 Template,61 """62 <%block name="x">63 block64 </%block>65 foob66 <%block name="x">67 block68 </%block>69 """,70 )71 def test_name_collision_blocks_nested_block(self):72 assert_raises_message(73 exceptions.CompileException,74 "%def or %block named 'x' already exists in this template",75 Template,76 """77 <%block>78 <%block name="x">79 block80 </%block>81 foob82 <%block name="x">83 block84 </%block>85 </%block>86 """,87 )88 def test_name_collision_blocks_nested_def(self):89 assert_raises_message(90 exceptions.CompileException,91 "Named block 'x' not allowed inside of def 'foo'",92 Template,93 """94 <%def name="foo()">95 <%block name="x">96 block97 </%block>98 foob99 <%block name="x">100 block101 </%block>102 </%def>103 """,104 )105 def test_name_collision_block_def_toplevel(self):106 assert_raises_message(107 exceptions.CompileException,108 "%def or %block named 'x' already exists in this template",109 Template,110 """111 <%block name="x">112 block113 </%block>114 foob115 <%def name="x()">116 block117 </%def>118 """,119 )120 def test_name_collision_def_block_toplevel(self):121 assert_raises_message(122 exceptions.CompileException,123 "%def or %block named 'x' already exists in this template",124 Template,125 """126 <%def name="x()">127 block128 </%def>129 foob130 <%block name="x">131 block132 </%block>133 """,134 )135 def test_named_block_renders(self):136 template = Template(137 """138 above139 <%block name="header">140 the header141 </%block>142 below143 """144 )145 self._do_test(146 template, ["above", "the header", "below"], filters=result_lines147 )148 def test_inherited_block_no_render(self):149 l = TemplateLookup()150 l.put_string(151 "index",152 """153 <%inherit file="base"/>154 <%block name="header">155 index header156 </%block>157 """,158 )159 l.put_string(160 "base",161 """162 above163 <%block name="header">164 the header165 </%block>166 ${next.body()}167 below168 """,169 )170 self._do_test(171 l.get_template("index"),172 ["above", "index header", "below"],173 filters=result_lines,174 )175 def test_no_named_in_def(self):176 assert_raises_message(177 exceptions.CompileException,178 "Named block 'y' not allowed inside of def 'q'",179 Template,180 """181 <%def name="q()">182 <%block name="y">183 </%block>184 </%def>185 """,186 )187 def test_inherited_block_nested_both(self):188 l = TemplateLookup()189 l.put_string(190 "index",191 """192 <%inherit file="base"/>193 <%block name="title">194 index title195 </%block>196 <%block name="header">197 index header198 ${parent.header()}199 </%block>200 """,201 )202 l.put_string(203 "base",204 """205 above206 <%block name="header">207 base header208 <%block name="title">209 the title210 </%block>211 </%block>212 ${next.body()}213 below214 """,215 )216 self._do_test(217 l.get_template("index"),218 ["above", "index header", "base header", "index title", "below"],219 filters=result_lines,220 )221 def test_inherited_block_nested_inner_only(self):222 l = TemplateLookup()223 l.put_string(224 "index",225 """226 <%inherit file="base"/>227 <%block name="title">228 index title229 </%block>230 """,231 )232 l.put_string(233 "base",234 """235 above236 <%block name="header">237 base header238 <%block name="title">239 the title240 </%block>241 </%block>242 ${next.body()}243 below244 """,245 )246 self._do_test(247 l.get_template("index"),248 ["above", "base header", "index title", "below"],249 filters=result_lines,250 )251 def test_noninherited_block_no_render(self):252 l = TemplateLookup()253 l.put_string(254 "index",255 """256 <%inherit file="base"/>257 <%block name="some_thing">258 some thing259 </%block>260 """,261 )262 l.put_string(263 "base",264 """265 above266 <%block name="header">267 the header268 </%block>269 ${next.body()}270 below271 """,272 )273 self._do_test(274 l.get_template("index"),275 ["above", "the header", "some thing", "below"],276 filters=result_lines,277 )278 def test_no_conflict_nested_one(self):279 l = TemplateLookup()280 l.put_string(281 "index",282 """283 <%inherit file="base"/>284 <%block>285 <%block name="header">286 inner header287 </%block>288 </%block>289 """,290 )291 l.put_string(292 "base",293 """294 above295 <%block name="header">296 the header297 </%block>298 ${next.body()}299 below300 """,301 )302 self._do_test(303 l.get_template("index"),304 ["above", "inner header", "below"],305 filters=result_lines,306 )307 def test_nested_dupe_names_raise(self):308 assert_raises_message(309 exceptions.CompileException,310 "%def or %block named 'header' already exists in this template.",311 Template,312 """313 <%inherit file="base"/>314 <%block name="header">315 <%block name="header">316 inner header317 </%block>318 </%block>319 """,320 )321 def test_two_levels_one(self):322 l = TemplateLookup()323 l.put_string(324 "index",325 """326 <%inherit file="middle"/>327 <%block name="header">328 index header329 </%block>330 <%block>331 index anon332 </%block>333 """,334 )335 l.put_string(336 "middle",337 """338 <%inherit file="base"/>339 <%block>340 middle anon341 </%block>342 ${next.body()}343 """,344 )345 l.put_string(346 "base",347 """348 above349 <%block name="header">350 the header351 </%block>352 ${next.body()}353 below354 """,355 )356 self._do_test(357 l.get_template("index"),358 ["above", "index header", "middle anon", "index anon", "below"],359 filters=result_lines,360 )361 def test_filter(self):362 template = Template(363 """364 <%block filter="h">365 <html>366 </%block>367 """368 )369 self._do_test(template, ["&lt;html&gt;"], filters=result_lines)370 def test_anon_in_named(self):371 template = Template(372 """373 <%block name="x">374 outer above375 <%block>376 inner377 </%block>378 outer below379 </%block>380 """381 )382 self._test_block_in_block(template)383 def test_named_in_anon(self):384 template = Template(385 """386 <%block>387 outer above388 <%block name="x">389 inner390 </%block>391 outer below392 </%block>393 """394 )395 self._test_block_in_block(template)396 def test_anon_in_anon(self):397 template = Template(398 """399 <%block>400 outer above401 <%block>402 inner403 </%block>404 outer below405 </%block>406 """407 )408 self._test_block_in_block(template)409 def test_named_in_named(self):410 template = Template(411 """412 <%block name="x">413 outer above414 <%block name="y">415 inner416 </%block>417 outer below418 </%block>419 """420 )421 self._test_block_in_block(template)422 def _test_block_in_block(self, template):423 self._do_test(424 template,425 ["outer above", "inner", "outer below"],426 filters=result_lines,427 )428 def test_iteration(self):429 t = Template(430 """431 % for i in (1, 2, 3):432 <%block>${i}</%block>433 % endfor434 """435 )436 self._do_test(t, ["1", "2", "3"], filters=result_lines)437 def test_conditional(self):438 t = Template(439 """440 % if True:441 <%block>true</%block>442 % endif443 % if False:444 <%block>false</%block>445 % endif446 """447 )448 self._do_test(t, ["true"], filters=result_lines)449 def test_block_overridden_by_def(self):450 l = TemplateLookup()451 l.put_string(452 "index",453 """454 <%inherit file="base"/>455 <%def name="header()">456 inner header457 </%def>458 """,459 )460 l.put_string(461 "base",462 """463 above464 <%block name="header">465 the header466 </%block>467 ${next.body()}468 below469 """,470 )471 self._do_test(472 l.get_template("index"),473 ["above", "inner header", "below"],474 filters=result_lines,475 )476 def test_def_overridden_by_block(self):477 l = TemplateLookup()478 l.put_string(479 "index",480 """481 <%inherit file="base"/>482 <%block name="header">483 inner header484 </%block>485 """,486 )487 l.put_string(488 "base",489 """490 above491 ${self.header()}492 <%def name="header()">493 the header494 </%def>495 ${next.body()}496 below497 """,498 )499 self._do_test(500 l.get_template("index"),501 ["above", "inner header", "below"],502 filters=result_lines,503 )504 def test_block_args(self):505 l = TemplateLookup()506 l.put_string(507 "caller",508 """509 <%include file="callee" args="val1='3', val2='4'"/>510 """,511 )512 l.put_string(513 "callee",514 """515 <%page args="val1, val2"/>516 <%block name="foob" args="val1, val2">517 foob, ${val1}, ${val2}518 </%block>519 """,520 )521 self._do_test(522 l.get_template("caller"), ["foob, 3, 4"], filters=result_lines523 )524 def test_block_variables_contextual(self):525 t = Template(526 """527 <%block name="foob" >528 foob, ${val1}, ${val2}529 </%block>530 """531 )532 self._do_test(533 t,534 ["foob, 3, 4"],535 template_args={"val1": 3, "val2": 4},536 filters=result_lines,537 )538 def test_block_args_contextual(self):539 t = Template(540 """541 <%page args="val1"/>542 <%block name="foob" args="val1">543 foob, ${val1}, ${val2}544 </%block>545 """546 )547 self._do_test(548 t,549 ["foob, 3, 4"],550 template_args={"val1": 3, "val2": 4},551 filters=result_lines,552 )553 def test_block_pageargs_contextual(self):554 t = Template(555 """556 <%block name="foob">557 foob, ${pageargs['val1']}, ${pageargs['val2']}558 </%block>559 """560 )561 self._do_test(562 t,563 ["foob, 3, 4"],564 template_args={"val1": 3, "val2": 4},565 filters=result_lines,566 )567 def test_block_pageargs(self):568 l = TemplateLookup()569 l.put_string(570 "caller",571 """572 <%include file="callee" args="val1='3', val2='4'"/>573 """,574 )575 l.put_string(576 "callee",577 """578 <%block name="foob">579 foob, ${pageargs['val1']}, ${pageargs['val2']}580 </%block>581 """,582 )583 self._do_test(584 l.get_template("caller"), ["foob, 3, 4"], filters=result_lines...

Full Screen

Full Screen

test_modulefinder.py

Source:test_modulefinder.py Github

copy

Full Screen

...295 finally:296 if ofi:297 ofi.close()298class ModuleFinderTest(unittest.TestCase):299 def _do_test(self, info, report=False, debug=0, replace_paths=[], modulefinder_class=modulefinder.ModuleFinder):300 import_this, modules, missing, maybe_missing, source = info301 create_package(source)302 try:303 mf = modulefinder_class(path=TEST_PATH, debug=debug,304 replace_paths=replace_paths)305 mf.import_hook(import_this)306 if report:307 mf.report()308## # This wouldn't work in general when executed several times:309## opath = sys.path[:]310## sys.path = TEST_PATH311## try:312## __import__(import_this)313## except:314## import traceback; traceback.print_exc()315## sys.path = opath316## return317 modules = sorted(set(modules))318 found = sorted(mf.modules)319 # check if we found what we expected, not more, not less320 self.assertEqual(found, modules)321 # check for missing and maybe missing modules322 bad, maybe = mf.any_missing_maybe()323 self.assertEqual(bad, missing)324 self.assertEqual(maybe, maybe_missing)325 finally:326 shutil.rmtree(TEST_DIR)327 def test_package(self):328 self._do_test(package_test)329 def test_maybe(self):330 self._do_test(maybe_test)331 def test_maybe_new(self):332 self._do_test(maybe_test_new)333 def test_absolute_imports(self):334 self._do_test(absolute_import_test)335 def test_relative_imports(self):336 self._do_test(relative_import_test)337 def test_relative_imports_2(self):338 self._do_test(relative_import_test_2)339 def test_relative_imports_3(self):340 self._do_test(relative_import_test_3)341 def test_relative_imports_4(self):342 self._do_test(relative_import_test_4)343 def test_syntax_error(self):344 self._do_test(syntax_error_test)345 def test_same_name_as_bad(self):346 self._do_test(same_name_as_bad_test)347 def test_bytecode(self):348 base_path = os.path.join(TEST_DIR, 'a')349 source_path = base_path + importlib.machinery.SOURCE_SUFFIXES[0]350 bytecode_path = base_path + importlib.machinery.BYTECODE_SUFFIXES[0]351 with open_file(source_path) as file:352 file.write('testing_modulefinder = True\n'.encode('utf-8'))353 py_compile.compile(source_path, cfile=bytecode_path)354 os.remove(source_path)355 self._do_test(bytecode_test)356 def test_replace_paths(self):357 old_path = os.path.join(TEST_DIR, 'a', 'module.py')358 new_path = os.path.join(TEST_DIR, 'a', 'spam.py')359 with support.captured_stdout() as output:360 self._do_test(maybe_test, debug=2,361 replace_paths=[(old_path, new_path)])362 output = output.getvalue()363 expected = "co_filename %r changed to %r" % (old_path, new_path)364 self.assertIn(expected, output)365 def test_extended_opargs(self):366 extended_opargs_test = [367 "a",368 ["a", "b"],369 [], [],370 """\371a.py372 %r373 import b374b.py375""" % list(range(2**16))] # 2**16 constants376 self._do_test(extended_opargs_test)377 def test_coding_default_utf8(self):378 self._do_test(coding_default_utf8_test)379 def test_coding_explicit_utf8(self):380 self._do_test(coding_explicit_utf8_test)381 def test_coding_explicit_cp1252(self):382 self._do_test(coding_explicit_cp1252_test)383 def test_load_module_api(self):384 class CheckLoadModuleApi(modulefinder.ModuleFinder):385 def __init__(self, *args, **kwds):386 super().__init__(*args, **kwds)387 def load_module(self, fqname, fp, pathname, file_info):388 # confirm that the fileinfo is a tuple of 3 elements389 suffix, mode, type = file_info390 return super().load_module(fqname, fp, pathname, file_info)391 self._do_test(absolute_import_test, modulefinder_class=CheckLoadModuleApi)392if __name__ == "__main__":...

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