How to use _run_tests method in stestr

Best Python code snippet using stestr_python

test_html_display.py

Source:test_html_display.py Github

copy

Full Screen

...232###############################################################################233# Unit test classes doon 'ere!234###############################################################################235class BaseTest(unittest.TestCase):236 def _run_tests(self, baseparser, input_text, expected_output):237 parser = baseparser(input_text)238 rendered_output = parser.render(getattr(parser, "render_context", None))239 self.assertEqual(240 expected_output,241 rendered_output,242 "NOT EQUAL!\nExpected:\n{expected}\n---\nActual:\n{actual}\n---\ntree:\n{tree}".format(243 expected=expected_output,244 actual=rendered_output,245 tree=parser.pretty_format(),246 ),247 )248class InlineTagTests(BaseTest):249 def test_render(self):250 self._run_tests(251 DefaultParser, "[b]bold tag[/b]", "<strong>bold tag</strong>",252 )253 def test_render_other_inline(self):254 self._run_tests(255 DefaultParser,256 "[b]bold[/b] and [i]italic[/i] tag",257 "<strong>bold</strong> and <em>italic</em> tag",258 )259 def test_dont_render_blocks(self):260 self._run_tests(261 DefaultParser,262 "[b]bold cant render [div]div[/div] tags[/b]",263 "<strong>bold cant render div tags</strong>",264 )265class BlockTagTests(BaseTest):266 def test_render(self):267 self._run_tests(268 DefaultParser,269 "text outside [div]text inside[/div] text outside",270 "text outside <div><p>text inside</p></div> text outside",271 )272 def test_render_inline(self):273 self._run_tests(274 DefaultParser,275 "text outside [div][b]text[/b]\n[i]inside[/i][/div] text outside",276 "text outside <div><p><strong>text</strong>\n<em>inside</em></p></div> text outside",277 )278 def test_render_blocks(self):279 self._run_tests(280 DefaultParser,281 "text outside [div]with another [div]div inside[/div][/div] text outside",282 "text outside <div><p>with another </p><div><p>div inside</p></div></div> text outside",283 )284class NewlineTests(BaseTest):285 def test_none(self):286 self._run_tests(287 NewlineParser, "no newlines in this copy", "no newlines in this copy",288 )289 def test_single(self):290 self._run_tests(291 NewlineParser,292 "there is one single\nnewline in this copy",293 "there is one single<br />newline in this copy",294 )295 """296 Multiple \n should only ever return a single <br />297 """298 def test_double(self):299 self._run_tests(300 NewlineParser,301 "there is two single\n\nnewline in this copy",302 "there is two single<br />newline in this copy",303 )304 def test_triple(self):305 self._run_tests(306 NewlineParser,307 "there is three single\n\n\nnewline in this copy",308 "there is three single<br />newline in this copy",309 )310 def test_true(self):311 self._run_tests(312 NewlineParser,313 "copy here [newline-true]a newline\nin this copy[/newline-true] copy here",314 "copy here <div>a newline<br />in this copy</div> copy here",315 )316 def test_false(self):317 self._run_tests(318 NewlineParser,319 "copy here [newline-false]a newline\nin this copy[/newline-false] copy here",320 "copy here <div>a newline\nin this copy</div> copy here",321 )322 def test_inherit(self):323 self._run_tests(324 NewlineParser,325 "copy here [newline-inherit]a newline\nin this copy[/newline-inherit] copy here",326 "copy here <div>a newline<br />in this copy</div> copy here",327 )328 def test_inherit_deeper(self):329 self._run_tests(330 NewlineParser,331 "copy here [newline-inherit]newline\n[newline-false][newline-inherit]no\nnewline[/newline-inherit][/newline-false][/newline-inherit] copy here",332 "copy here <div>newline<br /><div><div>no\nnewline</div></div></div> copy here",333 )334class ParagraphTests(BaseTest):335 def test_none(self):336 self._run_tests(337 ParagraphParser, "", "",338 )339 def test_single(self):340 self._run_tests(341 ParagraphParser,342 "paragraph around this copy",343 "<p>paragraph around this copy</p>",344 )345 def test_double(self):346 self._run_tests(347 ParagraphParser,348 "there is a paragraph here\n\nthere is a paragraph here",349 "<p>there is a paragraph here</p><p>there is a paragraph here</p>",350 )351 def test_inline(self):352 self._run_tests(353 ParagraphParser,354 "[b]bold text[/b]\n\n[b]more bold text[/b]",355 "<p><strong>bold text</strong></p><p><strong>more bold text</strong></p>",356 )357 def test_block(self):358 self._run_tests(359 ParagraphParser,360 "[div]a block is here[/div]some text is here[div]a block is here[/div]some text is here",361 "<div><p>a block is here</p></div><p>some text is here</p><div><p>a block is here</p></div><p>some text is here</p>",362 )363 def test_true(self):364 self._run_tests(365 ParagraphParser,366 "copy here [paragraph-true]wrapped in paragraphs\n\nwrapped in paragraphs[/paragraph-true] copy here",367 "<p>copy here </p><div><p>wrapped in paragraphs</p><p>wrapped in paragraphs</p></div><p> copy here</p>",368 )369 def test_false(self):370 self._run_tests(371 ParagraphParser,372 "copy here [paragraph-false]wrapped in paragraphs\n\nwrapped in paragraphs[/paragraph-false] copy here",373 "<p>copy here </p><div>wrapped in paragraphs\n\nwrapped in paragraphs</div><p> copy here</p>",374 )375 def test_inherit(self):376 self._run_tests(377 ParagraphParser,378 "copy here [paragraph-inherit]wrapped in paragraphs\n\nwrapped in paragraphs[/paragraph-inherit] copy here",379 "<p>copy here </p><div><p>wrapped in paragraphs</p><p>wrapped in paragraphs</p></div><p> copy here</p>",380 )381 def test_inherit_deeper(self):382 self._run_tests(383 ParagraphParser,384 "copy here [paragraph-inherit]wrapped in paragraphs\n\nwrapped in paragraphs[paragraph-false][paragraph-inherit]no paragraphs here[/paragraph-inherit][/paragraph-false][/paragraph-inherit] copy here",385 "<p>copy here </p><div><p>wrapped in paragraphs</p><p>wrapped in paragraphs</p><div><div>no paragraphs here</div></div></div><p> copy here</p>",386 )387 def test_keep_newlines(self):388 self._run_tests(389 ParagraphParser,390 "p1\n\np2\np2 still\n\np3",391 "<p>p1</p><p>p2\np2 still</p><p>p3</p>",392 )393class StripNewlinesTest(BaseTest):394 def test_none(self):395 self._run_tests(396 StripNewlinesParser, "no newlines here", "no newlines here",397 )398 def test_all(self):399 self._run_tests(400 StripNewlinesParser,401 "remove\n all these\n\n new \n\n\n\nlines",402 "remove all these new lines",403 )404 def test_true(self):405 self._run_tests(406 StripNewlinesParser,407 "strip newlines here\n[stripnewlines-true]and also\n\n here[/stripnewlines-true]",408 "strip newlines here<div>and also here</div>",409 )410 def test_false(self):411 self._run_tests(412 StripNewlinesParser,413 "strip newlines here\n[stripnewlines-false]and also\n\n here[/stripnewlines-false]",414 "strip newlines here<div>and also here</div>",415 )416 def test_inherit(self):417 self._run_tests(418 StripNewlinesParser,419 "strip newlines here\n[stripnewlines-inherit]and also\n\n here[/stripnewlines-inherit]",420 "strip newlines here<div>and also here</div>",421 )422 def test_inherit_deep(self):423 self._run_tests(424 StripNewlinesParser,425 "strip newlines here\n[stripnewlines-inherit]and also\n\n here[stripnewlines-false][stripnewlines-inherit]these wont\n\n\n\n go[/stripnewlines-inherit][/stripnewlines-false][/stripnewlines-inherit]",426 "strip newlines here<div>and also here<div><div>these wont go</div></div></div>",427 )428class NewlinesParagraphsTest(BaseTest):429 def test_words(self):430 self._run_tests(431 ParagraphNewlinesParser,432 "first paragraph\n\nsecond paragraph with newline\nand more content",433 "<p>first paragraph</p><p>second paragraph with newline<br />and more content</p>",434 )435 def test_inline(self):436 self._run_tests(437 ParagraphNewlinesParser,438 "first paragraph\n\nsecond [b]paragraph[/b] with [i]newline\nand more[/i] content",439 "<p>first paragraph</p><p>second <strong>paragraph</strong> with <em>newline<br />and more</em> content</p>",440 )441 def test_block(self):442 self._run_tests(443 ParagraphNewlinesParser,444 "[div]block to start[/div]then some copy[div]and another block\n\nand paragraph[/div]\n\nwith another paragraph",445 "<div><p>block to start</p></div><p>then some copy</p><div><p>and another block</p><p>and paragraph</p></div><p>with another paragraph</p>",446 )447 def test_inline_block(self):448 self._run_tests(449 ParagraphNewlinesParser,450 "[b]bold text[/b]\nline break[div][i]italic content[/i][/div]",451 "<p><strong>bold text</strong><br />line break</p><div><p><em>italic content</em></p></div>",452 )453 def test_no_br_in_between_blocks(self):454 self._run_tests(455 ParagraphNewlinesParser,456 "[div]This is a block[/div]\nThis content doesn't matter at all!",457 "<div><p>This is a block</p></div>\n<p>This content doesn&#x27;t matter at all!</p>",458 )459 def test_br_in_paragraph(self):460 self._run_tests(461 ParagraphNewlinesParser,462 "[b]A really nice sentence[/b]\n[div]a div tag[/div]",463 "<p><strong>A really nice sentence</strong>\n</p><div><p>a div tag</p></div>",464 )465 def test_newlines_before_paragraph(self):466 self._run_tests(467 ParagraphNewlinesParser,468 "\n[b]A really nice sentence[/b]\n",469 "\n<p><strong>A really nice sentence</strong>\n</p>",470 )471class ParagraphsStripNewlinesTest(BaseTest):472 def test_words(self):473 self._run_tests(474 StripNewlinesNotParagraphsParser,475 "first paragraph\n\nsecond paragraph with newline\n and more content",476 "<p>first paragraph</p><p>second paragraph with newline and more content</p>",477 )478 def test_inline(self):479 self._run_tests(480 StripNewlinesNotParagraphsParser,481 "first paragraph\n\nsecond [b]paragraph[/b] with [i]newline\n and more[/i] content",482 "<p>first paragraph</p><p>second <strong>paragraph</strong> with <em>newline and more</em> content</p>",483 )484 def test_block(self):485 self._run_tests(486 StripNewlinesNotParagraphsParser,487 "[div]block to\n start[/div]then some\n copy[div]and another block\n\nand paragraph[/div]\n\nwith another paragraph",488 "<div><p>block to start</p></div><p>then some copy</p><div><p>and another block</p><p>and paragraph</p></div><p>with another paragraph</p>",489 )490 def test_inline_block(self):491 self._run_tests(492 StripNewlinesNotParagraphsParser,493 "[b]bold text[/b]\nline break[div][i]italic content[/i][/div]",494 "<p><strong>bold text</strong>line break</p><div><p><em>italic content</em></p></div>",495 )496class RenderSelectedTagsTest(BaseTest):497 def test_render_tags(self):498 self._run_tests(499 RenderSelectedTagsParser, "[b]bold text[/b]", "<strong>bold text</strong>",500 )501 def test_render_raw_missing_tags(self):502 self._run_tests(503 RenderSelectedTagsParser,504 "[b]bold text[/b][unknown]dunno about this[/unknown]",505 "<strong>bold text</strong>[unknown]dunno about this[/unknown]",506 )507class ParentScopeTest(BaseTest):508 def test_no_paragraphs(self):509 input_text = "Line 1\n\nLine 2\n\nLine 3"510 parser = DefaultParser(input_text)511 root_node = parser.root_node512 for node in root_node.tree:513 self.assertEqual(node._parent_node, root_node)514 def test_with_paragraphs(self):515 input_text = "Line 1\n\nLine 2\n\nLine 3"516 parser = ParagraphParser(input_text)...

Full Screen

Full Screen

test_parsing.py

Source:test_parsing.py Github

copy

Full Screen

...5 test_cases = (6 ("0,0,0", ["0", "0", "0"]),7 ("0,a=0,a=0", ["0", "a=0", "a=0"]),8 )9 self._run_tests(test_cases)10 def test_commas_ignored_in_brackets(self):11 test_cases = (12 ("0,[0,0],0,[0,0],0", ["0", "[0,0]", "0", "[0,0]", "0"]),13 ("(0,),0,(0,(0,),0),0", ["(0,)", "0", "(0,(0,),0)", "0"]),14 )15 self._run_tests(test_cases)16 def test_mixed_brackets(self):17 tests_cases = (18 ("[0,{0},0],0,{0:0},0", ["[0,{0},0]", "0", "{0:0}", "0"]),19 ("([0],0,0),0,(0,0),0", ["([0],0,0)", "0", "(0,0)", "0"]),20 ("([(0,),(0,)],0),0", ["([(0,),(0,)],0)", "0"]),21 )22 self._run_tests(tests_cases)23 def test_string_contents_ignored(self):24 test_cases = (25 ("'0,0',0,',',0", ["'0,0'", "0", "','", "0"]),26 ("0,[']',0],0", ["0", "[']',0]", "0"]),27 ("{0,0,'}}',0,'{'},0", ["{0,0,'}}',0,'{'}", "0"]),28 )29 self._run_tests(test_cases)30 def test_mixed_quotes(self):31 test_cases = (32 ("\"0',0',\",'0,0',0", ["\"0',0',\"", "'0,0'", "0"]),33 ("\",',\",'\",',0", ["\",',\"", "'\",'", "0"]),34 )35 self._run_tests(test_cases)36 def test_quote_escaped(self):37 test_cases = (38 (r"'\',','\\',0", [r"'\','", r"'\\'", "0"]),39 (r"'0\',0\\\'\\',0", [r"'0\',0\\\'\\'", "0"]),40 )41 self._run_tests(test_cases)42 def test_real_signatures(self):43 test_cases = (44 ("start, stop[, step]", ["start", " stop[, step]"]),45 ("object=b'', encoding='utf-8', errors='strict'", ["object=b''", " encoding='utf-8'", " errors='strict'"]),46 (47 "typename, field_names, *, rename=False, defaults=None, module=None",48 ["typename", " field_names", " *", " rename=False", " defaults=None", " module=None"]49 ),50 )51 self._run_tests(test_cases)52 def _run_tests(self, test_cases):53 for input_string, expected_output in test_cases:54 with self.subTest(input_string=input_string):...

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