def _test(self, crit, noncrit, exp): test = BaseTestCase('Name', parent=None) critical = _Critical() critical.set(crit, noncrit) test.tags = ['tag1', 'tag2', 'tag3'] test.set_criticality(critical) assert_equals(test.critical, exp)
def test_exclude(self): for excl, tags in _incl_excl_data: tagstats = TagStatistics([], excl) tagstats.add_test(TestMock('PASS', tags), _Critical()) exp_keys = [tag for tag in sorted(tags) if not utils.matches_any(tag, excl)] assert_equal(sorted(tagstats.stats.keys()), exp_keys, "Excls: %s" % excl)
def __init__(self, name='My Name', crit_tags=None): self.name = name self.mediumname = self.get_medium_name() self.longname = self.get_long_name() self.critical = _Critical(crit_tags) self.suites = [] self.tests = [] self.message = ''
def test_exclude(self): for excl, tags in _incl_excl_data: tagstats = TagStatistics([], excl) tagstats.add_test(TestMock('PASS', tags), _Critical()) exp_keys = [ tag for tag in sorted(tags) if not utils.matches_any(tag, excl) ] assert_equal(sorted(tagstats.stats.keys()), exp_keys, "Excls: %s" % excl)
def test_include(self): for incl, tags in _incl_excl_data: tagstats = TagStatistics(incl, []) tagstats.add_test(TestMock('PASS', tags), _Critical()) keys = tagstats.stats.keys() keys.sort() tags.sort() exp_keys = [ tag for tag in tags if incl == [] or utils.matches_any(tag, incl) ] assert_equal(keys, exp_keys, "Incls: %s " % incl)
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 test_include_and_exclude(self): for incl, excl, tags, exp in [ ([], [], ['t0','t1','t2'], ['t0','t1','t2']), (['t1'], ['t2'], ['t0','t1','t2'], ['t1']), (['t?'], ['t2'], ['t0','t1','t2','x'], ['t0','t1']), (['t?'], ['*2'], ['t0','t1','t2','x2'], ['t0','t1']), (['t1','t2'], ['t2'], ['t0','t1','t2'], ['t1']), (['t1','t2','t3','not'], ['t2','t0'], ['t0','t1','t2','t3','x'], ['t1','t3'] ) ]: tagstats = TagStatistics(incl, excl) tagstats.add_test(TestMock('PASS', tags), _Critical()) assert_equal(sorted(tagstats.stats.keys()), exp, "Incls: %s, Excls: %s" % (incl, excl))
def test_include_and_exclude(self): for incl, excl, tags, exp in [ ([], [], ['t0', 't1', 't2'], ['t0', 't1', 't2']), (['t1'], ['t2'], ['t0', 't1', 't2'], ['t1']), (['t?'], ['t2'], ['t0', 't1', 't2', 'x'], ['t0', 't1']), (['t?'], ['*2'], ['t0', 't1', 't2', 'x2'], ['t0', 't1']), (['t1', 't2'], ['t2'], ['t0', 't1', 't2'], ['t1']), (['t1', 't2', 't3', 'not'], ['t2', 't0'], ['t0', 't1', 't2', 't3', 'x'], ['t1', 't3']) ]: tagstats = TagStatistics(incl, excl) tagstats.add_test(TestMock('PASS', tags), _Critical()) assert_equal(sorted(tagstats.stats.keys()), exp, "Incls: %s, Excls: %s" % (incl, excl))
def __init__(self, name='My Name', id='s1', crit_tags=None): self.name = self.longname = name self.id = id self.critical = _Critical(crit_tags) self.suites = [] self.tests = []