def should_contain_suites(self, suite, *suite_names): actual_names = [s.name for s in suite.suites] utils.asserts.assert_equals(len(actual_names), len(suite_names), 'Wrong number of subsuites') for expected in suite_names: if not any(utils.matches(expected, name) for name in actual_names): raise AssertionError('Suite %s not found' % expected)
def test_exclude(self): for excl, tags in self._incl_excl_data: builder = TagStatisticsBuilder(Criticality(), [], excl) builder.add_test(TestCase(status='PASS', tags=tags)) expected = [tag for tag in tags if not any(utils.matches(tag, e) for e in excl)] assert_equals([s.name for s in builder.stats], sorted(expected))
def test_exclude(self): for excl, tags in self._incl_excl_data: builder = TagStatisticsBuilder(Criticality(), [], excl) builder.add_test(TestCase(status='PASS', tags=tags)) expected = [ tag for tag in tags if not any(utils.matches(tag, e) for e in excl) ] assert_equals([s.name for s in builder.stats], sorted(expected))
def _matches_tag(self, tag): """Returns True if given tag matches any tag from self.tags. Note that given tag may be ANDed combination of multiple tags (e.g. tag1&tag2) and then all of them must match some tag from self.tags. """ for item in tag.split('&'): if not any(utils.matches(t, item, ignore=['_']) for t in self.tags): return False return True
def check_suite_contains_tests(self, suite, *expected_names): actual_tests = [test for test in self.get_tests_from_suite(suite)] tests_msg = """ Expected tests : %s Actual tests : %s""" % (str(list(expected_names)), str(actual_tests)) expected_names = [utils.normalize(name) for name in expected_names] if len(actual_tests) != len(expected_names): raise AssertionError("Wrong number of tests." + tests_msg) for test in actual_tests: if any(utils.matches(test.name, name) for name in expected_names): print "Verifying test '%s'" % test.name self.check_test_status(test) expected_names.remove(utils.normalize(test.name)) else: raise AssertionError("Test '%s' was not expected to be run.%s" % (test.name, tests_msg)) assert not expected_names
def _get_get_file_sources(self, source, path_separator): if path_separator in source: path, pattern = source.rsplit(path_separator, 1) else: path, pattern = '', source if not path: path = '.' sourcefiles = [] for filename in self._listfiles(path): if utils.matches(filename, pattern): if path: filename = path_separator.join([path, filename]) sourcefiles.append(filename) if not sourcefiles: msg = "There were no source files matching '%s'" % source raise SSHClientException(msg) return sourcefiles
def _filter_suite_name(self, parent, suite): if utils.matches(self.name, suite[0], ignore=['_']): if len(suite) == 1: raise StopIteration('Match found') return (parent + [suite[0]], suite[1:]) return ([], parent + suite)
def should_contain_suites(self, suite, *suite_names): actual_names = [s.name for s in suite.suites] assert_equals(len(actual_names), len(suite_names), 'Wrong number of subsuites') for expected in suite_names: if not any(utils.matches(expected, name) for name in actual_names): raise AssertionError('Suite %s not found' % expected)
def matches(self, tag): return utils.matches(tag, self._pattern, ignore=['_'])
def get_doc(self, tag): docs = [] for pattern, doc in self._docs: if utils.matches(tag, pattern): docs.append(doc) return docs and ' '.join(docs) or None
def value_contains_variable(value, varname): return matches(value, "*%s*" % varname)
def matches(self, tag): return utils.matches(tag, self._pattern)