def test_filter_initialization_error(self): """ Symbol ":" or "::" can be used as delimiter and MAX_LEVEL parts can be generated for matching. """ with pytest.raises(ValueError): filtering.Pattern("foo:bar:baz:bat")
def test_filter_initialization_error(self): """ Pattern filter should raise error if pattern depth exceeds MAX_LEVEL """ with pytest.raises(ValueError): filtering.Pattern('foo:bar:baz:bat')
def run_testcases_iter(self, testsuite_pattern="*", testcase_pattern="*"): """Run all testcases and yield testcase reports.""" pattern = filtering.Pattern("*:{}:{}".format(testsuite_pattern, testcase_pattern)) testsuites = self.get_test_context(test_filter=pattern) for testsuite, testcases in testsuites: if not self.active: break # In python 3 we would use "yield from" but have to explicitly write # out the loop for python 2 support... for testcase_report, parent_uids in self._run_testsuite_iter( testsuite, testcases): yield testcase_report, parent_uids
def test_filter_parametrized_cases(self): """ Test filtering parametrized testcases. Parametrized testcases should match filter patterns for either the base parametrization template or the generated testcase name. """ suite = Delta() testcases = suite.get_testcases() assert len(testcases) == 3 # Expect 3 testcases to be generated. testcase = testcases[0] for pattern in ["*:Delta:parametrized", "*:Delta:parametrized__val_1"]: filter_obj = filtering.Pattern(pattern=pattern) assert filter_obj.filter_case(testcase)
def run_testcases_iter(self, testsuite_pattern="*", testcase_pattern="*"): """Run all testcases and yield testcase reports.""" test_filter = filtering.Pattern( pattern="*:{}:{}".format(testsuite_pattern, testcase_pattern), match_definition=True, ) for testsuite, testcases in self.test_context: if not self.active: break # In interactive mode testcases are selected to run, thus # an extra ``filtering.Pattern`` instance will be applied. testcases = [ testcase for testcase in testcases if test_filter.filter( test=self, suite=testsuite, case=testcase) ] if testcases:
def run_testcases_iter(self, testsuite_pattern="*", testcase_pattern="*"): """Run all testcases and yield testcase reports.""" test_filter = filtering.Pattern( pattern="*:{}:{}".format(testsuite_pattern, testcase_pattern), match_definition=True, ) for testsuite, testcases in self.test_context: if not self.active: break # In interactive mode testcases are selected to run, thus # an extra ``filtering.Pattern`` instance will be applied. testcases = [ testcase for testcase in testcases if test_filter.filter( test=self, suite=testsuite, case=testcase) ] # In python 3 we would use "yield from" but have to explicitly # write out the loop for python 2 support... for testcase_report, parent_uids in self._run_testsuite_iter(
" test_c", " Beta", " test_a", " test_b", " test_c", "Secondary", " Gamma", " test_a", " test_b", " test_c", ), ), # Custom sort / Custom filter / name listing ( listing.ExpandedNameLister(), filtering.Pattern("*:Alpha") | filtering.Pattern("*:Beta"), ordering.AlphanumericSorter(), to_stdout( "Primary", " Alpha", " test_a", " test_b", " test_c", " Beta", " test_a", " test_b", " test_c", ), ), ], )
def test_filter_case(self, pattern, testcase_obj, expected): filter_obj = filtering.Pattern(pattern=pattern) assert bool(filter_obj.filter_case(testcase_obj)) == expected
def test_filter_suite(self, pattern, testsuite_obj, expected): filter_obj = filtering.Pattern(pattern=pattern) # Test suite object gets its `name` after added into a Multitest MultiTest(name="MTest", suites=testsuite_obj) assert bool(filter_obj.filter_suite(testsuite_obj)) == expected
def test_filter_test(self, pattern, multitest, expected): filter_obj = filtering.Pattern(pattern) assert bool(filter_obj.filter_test(multitest)) == expected
@testcase(tags={'color': ('red', 'green')}) def test_three(self, env, result): pass @pytest.mark.parametrize( 'filter_obj, report_ctx', ( # Case 1 (filtering.Filter(), [('XXX', [ ('Alpha', ['test_one', 'test_two', 'test_three']), ('Beta', ['test_one', 'test_two', 'test_three']), ]), ('YYY', (('Gamma', ['test_one', 'test_two', 'test_three']), ))]), # Case 2 (filtering.Pattern('*:*:test_two'), [('XXX', [ ('Alpha', ['test_two']), ('Beta', ['test_two']), ]), ('YYY', [ ('Gamma', ['test_two']), ])]), # Case 3 (filtering.Pattern('XXX:Beta:test_two'), [ ('XXX', [('Beta', ['test_two'])]), ]), # Case 4 - testcase name match AND tag match (filtering.And(filtering.Pattern('*:*:test_two'), filtering.Tags({'color': 'blue'})), [('XXX', [ ('Alpha', ['test_two']), ]), ('YYY', [ ('Gamma', ['test_two']),
' Alpha', ' test_a', ' test_b', ' test_c', ' Beta', ' test_a', ' test_b', ' test_c', 'Secondary', ' Gamma', ' test_a', ' test_b', ' test_c', )), # Custom sort / Custom filter / name listing (listing.ExpandedNameLister(), filtering.Pattern('*:Alpha') | filtering.Pattern('*:Beta'), ordering.AlphanumericSorter(), to_stdout( 'Primary', ' Alpha', ' test_a', ' test_b', ' test_c', ' Beta', ' test_a', ' test_b', ' test_c', )), ]) def test_programmatic_listing(listing_obj, filter_obj, sorter_obj, expected_output):
# Count lister, just lists top level test instances with the number of # suites & testcases. count_lister = listing.CountLister() # Sample output: # Primary: (2 suites, 6 testcases) # Secondary: (1 suite, 102 testcases) # Here is a list of filters, you can pass them to # the test plan declaration below and see how they change the # test listing output. pattern_filter_1 = filtering.Pattern('Primary') pattern_filter_2 = filtering.Pattern('*:*:test_c') tag_filter_1 = filtering.Tags('client') tag_filter_2 = filtering.Tags({'color': 'blue'}) composite_filter_1 = pattern_filter_1 | pattern_filter_2 composite_filter_2 = (pattern_filter_1 & tag_filter_1) | tag_filter_2 @test_plan( name='Programmatic Listing Example', # You can replace this argument with the other listers defined above # to see different output formats. # test_lister=test_lister, test_lister=name_lister,
( filtering.Filter(), [ ( "XXX", [ ("Alpha", ["test_one", "test_two", "test_three"]), ("Beta", ["test_one", "test_two", "test_three"]), ], ), ("YYY", (("Gamma", ["test_one", "test_two", "test_three"]),)), ], ), # Case 2 ( filtering.Pattern("*:*:test_two"), [ ("XXX", [("Alpha", ["test_two"]), ("Beta", ["test_two"])]), ("YYY", [("Gamma", ["test_two"])]), ], ), # Case 3 ( filtering.Pattern("XXX:Beta:test_two"), [("XXX", [("Beta", ["test_two"])])], ), # Case 4 - testcase name match AND tag match ( filtering.And( filtering.Pattern("*:*:test_two"), filtering.Tags({"color": "blue"}),
# Count lister, just lists top level test instances with the number of # suites & testcases. count_lister = listing.CountLister() # Sample output: # Primary: (2 suites, 6 testcases) # Secondary: (1 suite, 102 testcases) # Here is a list of filters, you can pass them to # the test plan declaration below and see how they change the # test listing output. pattern_filter_1 = filtering.Pattern("Primary") pattern_filter_2 = filtering.Pattern("*:*:test_c") tag_filter_1 = filtering.Tags("client") tag_filter_2 = filtering.Tags({"color": "blue"}) composite_filter_1 = pattern_filter_1 | pattern_filter_2 composite_filter_2 = (pattern_filter_1 & tag_filter_1) | tag_filter_2 @test_plan( name="Programmatic Listing Example", # You can replace this argument with the other listers defined above # to see different output formats. # test_lister=test_lister, test_lister=name_lister,