def test_combine(self): # This is more like an acceptance test than a unit test ... for comb_tags, tests_tags, crit_tags in [ (['t1&t2'], [['t1','t2','t3'],['t1','t3']], []), (['1&2&3'], [['1','2','3'],['1','2','3','4']], ['1','2']), (['1&2','1&3'], [['1','2','3'],['1','3'],['1']], ['1']), (['t*'], [['t1','x','y'],['tee','z'],['t']], ['x']), (['t?&s'], [['t1','s'],['tt','s','u'],['tee','s'],['s']], []), (['t*&s','*'], [['s','t','u'],['tee','s'],[],['x']], []), (['tNOTs'], [['t','u'],['t','s']], []), (['tNOTs','t&s','tNOTsNOTu', 't&sNOTu'], [['t','u'],['t','s'],['s','t','u'],['t'],['t','v']], ['t']), (['nonex'], [['t1'],['t1,t2'],[]], []) ]: # 1) Create tag stats builder = TagStatisticsBuilder(Criticality(crit_tags), combined=[(t, '') for t in comb_tags]) all_tags = [] for tags in tests_tags: builder.add_test(TestCase(status='PASS', tags=tags),) all_tags.extend(tags) # 2) Actual values names = [stat.name for stat in builder.stats] # 3) Expected values exp_crit = []; exp_noncr = [] for tag in utils.normalize_tags(all_tags): if tag in crit_tags: exp_crit.append(tag) else: exp_noncr.append(tag) exp_names = exp_crit + sorted(comb_tags) + exp_noncr # 4) Verify names (match counts were already verified) assert_equals(names, exp_names)
def _convert_test(self, test): return { 'name': test.name, 'fullName': test.longname, 'id': test.id, 'doc': self._html(test.doc), 'tags': utils.normalize_tags(test.tags), 'timeout': self._get_timeout(test.timeout), 'keywords': list(self._convert_keywords(test)) }
def test_combine(self): # This test is more like an acceptance test than a unit test and # is doing too much... for comb_tags, comb_matches, tests_tags, crit_tags in [ (['t1&t2'], [1], [['t1', 't2', 't3'], ['t1', 't3']], []), (['1&2&3'], [2], [['1', '2', '3'], ['1', '2', '3', '4']], ['1', '2']), (['1&2', '1&3'], [1, 2], [['1', '2', '3'], ['1', '3'], ['1']], ['1']), (['t*'], [3], [['t1', 'x', 'y'], ['tee', 'z'], ['t']], ['x']), (['t?&s'], [2], [['t1', 's'], ['tt', 's', 'u'], ['tee', 's'], ['s']], []), (['t*&s', '*'], [2, 3], [['s', 't', 'u'], ['tee', 's'], [], ['x']], []), (['tNOTs'], [1], [['t', 'u'], ['t', 's']], []), (['tNOTs', 't&s', 'tNOTsNOTu', 't&sNOTu'], [3, 2, 2, 1], [['t', 'u'], ['t', 's'], ['s', 't', 'u'], ['t'], ['t', 'v']], ['t']), (['nonex'], [0], [['t1'], ['t1,t2'], []], []) ]: # 1) Create tag stats tagstats = TagStatistics([], [], comb_tags) all_tags = [] for tags in tests_tags: tagstats.add_test(TestMock('PASS', tags), _Critical(crit_tags)) all_tags.extend(tags) # 2) Actual values stats = tagstats.stats.values() stats.sort() # sorts crit first, then comb, then non-crit names = [stat.name for stat in stats] # 3) Expected values exp_crit = [] exp_noncr = [] exp_comb = [] for tag in utils.normalize_tags(all_tags): if tag in crit_tags: exp_crit.append(tag) else: exp_noncr.append(tag) for comb, count in zip(comb_tags, comb_matches): name = comb.replace('&', ' & ').replace('NOT', ' NOT ') exp_comb.append(name) try: assert_equals(len(tagstats.stats[name].tests), count) except KeyError: fail("No key %s. Stats: %s" % (name, tagstats.stats)) exp_comb.sort() exp_names = exp_crit + exp_comb + exp_noncr # 4) Verify names (match counts were already verified) assert_equals(names, exp_names)
def _init_test(self, context): errors = [] self.doc = context.replace_vars_from_setting("Documentation", self.doc, errors) self.setup.replace_variables(context.get_current_vars(), errors) self.teardown.replace_variables(context.get_current_vars(), errors) tags = context.replace_vars_from_setting("Tags", self.tags, errors) self.tags = utils.normalize_tags(tags) self.timeout.replace_variables(context.get_current_vars()) if errors: return "Test case initialization failed:\n%s" % "\n".join(errors) if not self.name: return "Test case name is required." if not self.keywords: return "Test case contains no keywords" return None
def _init_test(self, context): errors = [] self.doc = context.replace_vars_from_setting('Documentation', self.doc, errors) self.setup.replace_variables(context.get_current_vars(), errors) self.teardown.replace_variables(context.get_current_vars(), errors) tags = context.replace_vars_from_setting('Tags', self.tags, errors) self.tags = utils.normalize_tags(tags) self.timeout.replace_variables(context.get_current_vars()) if errors: return 'Test case initialization failed:\n%s' % '\n'.join(errors) if not self.name: return 'Test case name is required.' if not self.keywords: return 'Test case contains no keywords' return None
def test_combine(self): # This is more like an acceptance test than a unit test ... for comb_tags, tests_tags, crit_tags in [ (['t1&t2'], [['t1', 't2', 't3'], ['t1', 't3']], []), (['1&2&3'], [['1', '2', '3'], ['1', '2', '3', '4']], ['1', '2']), (['1&2', '1&3'], [['1', '2', '3'], ['1', '3'], ['1']], ['1']), (['t*'], [['t1', 'x', 'y'], ['tee', 'z'], ['t']], ['x']), (['t?&s'], [['t1', 's'], ['tt', 's', 'u'], ['tee', 's'], ['s']], []), (['t*&s', '*'], [['s', 't', 'u'], ['tee', 's'], [], ['x']], []), (['tNOTs'], [['t', 'u'], ['t', 's']], []), (['tNOTs', 't&s', 'tNOTsNOTu', 't&sNOTu'], [['t', 'u'], ['t', 's'], ['s', 't', 'u'], ['t'], ['t', 'v']], ['t']), (['nonex'], [['t1'], ['t1,t2'], []], []) ]: # 1) Create tag stats builder = TagStatisticsBuilder(Criticality(crit_tags), combined=[(t, '') for t in comb_tags]) all_tags = [] for tags in tests_tags: builder.add_test(TestCase(status='PASS', tags=tags), ) all_tags.extend(tags) # 2) Actual values names = [stat.name for stat in builder.stats] # 3) Expected values exp_crit = [] exp_noncr = [] for tag in utils.normalize_tags(all_tags): if tag in crit_tags: exp_crit.append(tag) else: exp_noncr.append(tag) exp_names = exp_crit + sorted(comb_tags) + exp_noncr # 4) Verify names (match counts were already verified) assert_equals(names, exp_names)
def test_remove_dupes(self): for inp in ['dupe', 'DUPE', ' d u p e '], ['d U', 'du', 'DU', 'Du']: assert_equals(normalize_tags(inp), [inp[0]])
def test_sorting(self): for inp, exp in [(['SORT', '1', 'B', '2', 'a'], ['1', '2', 'a', 'B', 'SORT']), (['all', 'A L L', 'NONE', '10', '1', 'A', 'a', ''], ['1', '10', 'A', 'all'])]: assert_equals(normalize_tags(inp), exp)
def test_sorting(self): for inp, exp in [(['SORT','1','B','2','a'], ['1','2','a','B','SORT']), (['all', 'A L L', 'NONE', '10', '1', 'A', 'a', ''], ['1', '10', 'A', 'all'])]: assert_equals(normalize_tags(inp), exp)
def test_sorting(self): for inp, exp in [ (["SORT", "1", "B", "2", "a"], ["1", "2", "a", "B", "SORT"]), (["all", "A L L", "NONE", "10", "1", "A", "a", ""], ["1", "10", "A", "all"]), ]: assert_equals(normalize_tags(inp), exp)
def test_case_and_space(self): for inp in ['lower'], ['MiXeD', 'UPPER'], ['a few', 'spaces here']: assert_equals(normalize_tags(inp), inp)
def test_remove_empty_and_none(self): for inp in ['', 'X', '', ' ', '\n'], ['none', 'N O N E', 'X', '', '_']: assert_equals(normalize_tags(inp), ['X'])
def _get_tags(self, tags): if isinstance(tags, utils.MultiMatcher): return tags return utils.MultiMatcher(utils.normalize_tags(tags or []), ignore=['_'])
def _tags(self, tags): if isinstance(tags, basestring): tags = [tags] return normalize_tags(tags or [])
def set_tags(self, tags): if tags: for test in self.tests: test.tags = utils.normalize_tags(test.tags + tags) for suite in self.suites: suite.set_tags(tags)
def _tags(self, tags): if isinstance(tags, basestring): tags = [tags] return utils.normalize_tags(tags or [])
def test_remove_dupes(self): for inp in ["dupe", "DUPE", " d u p e "], ["d U", "du", "DU", "Du"]: assert_equals(normalize_tags(inp), [inp[0]])
def set(self, tags, nons): self.tags = utils.normalize_tags(tags or []) self.nons = utils.normalize_tags(nons or [])
def test_case_and_space(self): for inp in ["lower"], ["MiXeD", "UPPER"], ["a few", "spaces here"]: assert_equals(normalize_tags(inp), inp)
def test_remove_empty_and_none(self): for inp in ["", "X", "", " ", "\n"], ["none", "N O N E", "X", "", "_"]: assert_equals(normalize_tags(inp), ["X"])
def test_underscore(self): assert_equals(normalize_tags(["a_tag", "a tag", "ATag"]), ["a_tag"]) assert_equals(normalize_tags(["tag", "_t_a_g_"]), ["tag"])
def test_no_tasg(self): assert_equals(normalize_tags([]), [])
def test_underscore(self): assert_equals(normalize_tags(['a_tag', 'a tag', 'ATag']), ['a_tag']) assert_equals(normalize_tags(['tag', '_t_a_g_']), ['tag'])