def build_suite(self, test_labels=None, extra_tests=None, **kwargs): suite = TestSuite() test_labels = test_labels or ['.'] extra_tests = extra_tests or [] discover_kwargs = {} if self.pattern is not None: discover_kwargs['pattern'] = self.pattern if self.top_level is not None: discover_kwargs['top_level_dir'] = self.top_level for label in test_labels: kwargs = discover_kwargs.copy() tests = None label_as_path = os.path.abspath(label) # if a module, or "module.ClassName[.method_name]", just run those if not os.path.exists(label_as_path): tests = self.test_loader.loadTestsFromName(label) elif os.path.isdir(label_as_path) and not self.top_level: # Try to be a bit smarter than unittest about finding the # default top-level for a given directory path, to avoid # breaking relative imports. (Unittest's default is to set # top-level equal to the path, which means relative imports # will result in "Attempted relative import in non-package."). # We'd be happy to skip this and require dotted module paths # (which don't cause this problem) instead of file paths (which # do), but in the case of a directory in the cwd, which would # be equally valid if considered as a top-level module or as a # directory path, unittest unfortunately prefers the latter. top_level = label_as_path while True: init_py = os.path.join(top_level, '__init__.py') if os.path.exists(init_py): try_next = os.path.dirname(top_level) if try_next == top_level: # __init__.py all the way down? give up. break top_level = try_next continue break kwargs['top_level_dir'] = top_level if not (tests and tests.countTestCases()): # if no tests found, it's probably a package; try discovery tests = self.test_loader.discover(start_dir=label, **kwargs) # make unittest forget the top-level dir it calculated from the # run, to support running tests from two different top-levels. self.test_loader._top_level_dir = None suite.addTests(tests) for test in extra_tests: suite.addTest(test) return reorder_suite(suite, self.reorder_by)
def build_suite(self, *args, **kwargs): suite = super(NonGeoTestRunner, self).build_suite(*args, **kwargs) filtered_suite = TestSuite() filtered_suite.addTests([ test for test in suite if test.__class__.__name__ != 'GeoMethodTestCase' ]) return filtered_suite
def load_tests(loader, standard_tests, _): suite = TestSuite() suite.addTests(standard_tests) for incorporating in user_factories: for incorporated in user_factories: test_case = build_test_case(incorporating, incorporated) tests = loader.loadTestsFromTestCase(test_case) suite.addTests(tests) return suite
def crud_suite(): suite = TestSuite() suite.addTest(defaultTestLoader.loadTestsFromTestCase(CreateTest)) suite.addTest(defaultTestLoader.loadTestsFromTestCase(ReadTest)) suite.addTest(defaultTestLoader.loadTestsFromTestCase(UpdateTest)) suite.addTest(defaultTestLoader.loadTestsFromTestCase(DeleteTest)) return suite
def build_suite(self, test_labels=None, extra_tests=None, **kwargs): suite = TestSuite() test_labels = test_labels or ['.'] extra_tests = extra_tests or [] discover_kwargs = {} if self.pattern is not None: discover_kwargs['pattern'] = self.pattern if self.top_level is not None: discover_kwargs['top_level_dir'] = self.top_level for label in test_labels: kwargs = discover_kwargs.copy() tests = None label_as_path = os.path.abspath(label) # if a module, or "module.ClassName[.method_name]", just run those if not os.path.exists(label_as_path): tests = self.test_loader.loadTestsFromName(label) elif os.path.isdir(label_as_path) and not self.top_level: # Try to be a bit smarter than unittest about finding the # default top-level for a given directory path, to avoid # breaking relative imports. (Unittest's default is to set # top-level equal to the path, which means relative imports # will result in "Attempted relative import in non-package."). # We'd be happy to skip this and require dotted module paths # (which don't cause this problem) instead of file paths (which # do), but in the case of a directory in the cwd, which would # be equally valid if considered as a top-level module or as a # directory path, unittest unfortunately prefers the latter. top_level = label_as_path while True: init_py = os.path.join(top_level, '__init__.py') if os.path.exists(init_py): try_next = os.path.dirname(top_level) if try_next == top_level: # __init__.py all the way down? give up. break top_level = try_next continue break kwargs['top_level_dir'] = top_level if not (tests and tests.countTestCases()): # if no tests found, it's probably a package; try discovery tests = self.test_loader.discover(start_dir=label, **kwargs) # make unittest forget the top-level dir it calculated from this # run, to support running tests from two different top-levels. self.test_loader._top_level_dir = None suite.addTests(tests) for test in extra_tests: suite.addTest(test) return reorder_suite(suite, self.reorder_by)
def test_allrun(self): loader = TestLoader() base_per_player_base = loader.loadTestsFromTestCase(TestBasePerPlayerBase) player_tutorial = loader.loadTestsFromTestCase(TestPlayerTutorial) player_deck = loader.loadTestsFromTestCase(TestPlayerDeck) player_treasure = loader.loadTestsFromTestCase(TestPlayerTreasure) player_trade_shop = loader.loadTestsFromTestCase(TestPlayerTradeShop) player_login = loader.loadTestsFromTestCase(TestPlayerLogin) player_login_time_limited = loader.loadTestsFromTestCase(TestPlayerLoginTimeLimited) rare_card_log = loader.loadTestsFromTestCase(TestRareCardLog) tests = TestSuite([base_per_player_base, player_tutorial, player_deck, player_treasure, player_trade_shop, player_login, player_login_time_limited, rare_card_log]) TextTestRunner().run(tests)
def suite(): "Builds a test suite for the GEOS tests." s = TestSuite() for suite in test_suites: s.addTest(suite) return s
self.assertEqual(cached_value, 'my_value') def test_zones(self): zonecache.add('my_key', 'my_value', zone='my_zone') cached_value = zonecache.get('my_key', zone='my_zone') self.assertEqual(cached_value, 'my_value') zonecache.invalidate_zone('my_zone') cached_value = zonecache.get('my_key', zone='my_zone') self.assertEqual(cached_value, None) zonecache.add('my_key', 'my_value', zone='my_zone') cached_value = zonecache.get('my_key', zone='my_zone') self.assertEqual(cached_value, 'my_value') def test_zone_version(self): zonecache.invalidate_zone('my_zone') zonecache.add('my_key', 'my_value', version=2, zone='my_zone') zonecache.add('my_key', 'my_value_2', version=3, zone='my_zone') cached_value = zonecache.get('my_key', version=2, zone='my_zone') self.assertEqual(cached_value, 'my_value') cached_value = zonecache.get('my_key', version=3, zone='my_zone') self.assertEqual(cached_value, 'my_value_2') suite = TestSuite() suite.addTest(makeSuite(ZoneCacheTest))
def suite(): "Builds a test suite for the GEOS tests." s = TestSuite() map(s.addTest, test_suites) return s
def suite(): "Builds a test suite for the GDAL tests." s = TestSuite() for test_suite in test_suites: s.addTest(test_suite) return s
def build_suite(self, test_labels, extra_tests=None, **kwargs): suite = TestSuite() signals.build_suite.send(sender=self, suite=suite) return reorder_suite(suite, (TestCase, ))
def suite(): suite = TestSuite() suite.addTest(crud_suite()) return suite