def add_suite(self, name, defs): if not defs: return unittest.TestSuite() elif isinstance(defs, list): return self.add_tests(name, defs) elif isinstance(defs, dict): return self.add_suites(name, defs) else: raise RuntimeError('invalid suite definition: %s' % defs)
def test_can_collect_new_tests(self): tests = [self.Test('test_name_%d' % i) for i in range(4)] suite = unittest.TestSuite(tests[:2]) results = list(self.db.collect_changes(suite)) results | should | each_be_equal_to([ 'test_name_0 (vows.test_db.Test)', 'test_name_1 (vows.test_db.Test)', ]) self.add_result(tests[0]) self.add_result(tests[1]) suite = unittest.TestSuite(tests) results = list(self.db.collect_changes(suite)) results | should | each_be_equal_to([ 'test_name_2 (vows.test_db.Test)', 'test_name_3 (vows.test_db.Test)', ])
def test_excludes_by_test_method_decorator(self): class Test(unittest.TestCase): @tag('include') def test_method(self): pass suite = unittest.TestSuite([Test('test_method')]) tags = TagExpression('~@include') filtered = tags.filter_suite(suite) map(str, filtered) | should | each_be_equal_to([])
def test_can_collect_tests_that_have_changed(self): tests = [self.Test('test_name_%d' % i) for i in range(4)] for test in tests: self.add_result(test) self.Test.test_name_2 = lambda self: None tests = [self.Test('test_name_%d' % i) for i in range(4)] suite = unittest.TestSuite(tests) results = list(self.db.collect_changes(suite)) results | should | each_be_equal_to([ 'test_name_2 (vows.test_db.Test)', ])
def test_includes_by_test_case_decorator(self): @tag('include') class Test(unittest.TestCase): def test_method(self): pass suite = unittest.TestSuite([Test('test_method')]) tags = TagExpression('@include') filtered = tags.filter_suite(suite) map(str, filtered) | should | each_be_equal_to([ 'test_method (vows.test_tags.Test)', ])
def add_suites(self, name, defs): return unittest.TestSuite( self.add_suite('_'.join((name, key)), value) for key, value in sorted(defs.items()))