Skip to content
Myr

Added nicer test finder from Flask

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 3b76f04 · Browse files · 5 files+67 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+67 added−3 removed

  • other:+67 added−3 removed

5 files+67 added−3 removed

modified:jinja2/testsuite/__init__.py+59 added
67 unmodified lines
68 else:69 self.fail('Expected exception')707172def find_all_tests(suite):73 """Yields all the tests and their names from a given suite."""74 suites = [suite]75 while suites:76 s = suites.pop()77 try:78 suites.extend(s)79 except TypeError:80 yield s, '%s.%s.%s' % (81 s.__class__.__module__,82 s.__class__.__name__,83 s._testMethodName84 )858687class BetterLoader(unittest.TestLoader):88 """A nicer loader that solves two problems. First of all we are setting89 up tests from different sources and we're doing this programmatically90 which breaks the default loading logic so this is required anyways.91 Secondly this loader has a nicer interpolation for test names than the92 default one so you can just do ``run-tests.py ViewTestCase`` and it93 will work.94 """9596 def getRootSuite(self):97 return suite()9899 def loadTestsFromName(self, name, module=None):100 root = self.getRootSuite()101 if name == 'suite':102 return root103104 all_tests = []105 for testcase, testname in find_all_tests(root):106 if testname == name or \107 testname.endswith('.' + name) or \108 ('.' + name + '.') in testname or \109 testname.startswith(name + '.'):110 all_tests.append(testcase)111112 if not all_tests:113 raise LookupError('could not find test case for "%s"' % name)114115 if len(all_tests) == 1:116 return all_tests[0]117 rv = unittest.TestSuite()118 for test in all_tests:119 rv.addTest(test)120 return rv121122123def suite():124 from jinja2.testsuite import ext, filters, tests, core_tags, \125 loader, inheritance, imports, lexnparse, security, api, \126 regression, debug, utils, doctests
17 unmodified lines
144 if PY2:145 suite.addTest(doctests.suite())146147 return suite148149150def main():151 """Runs the testsuite as command line application."""152 try:153 unittest.main(testLoader=BetterLoader(), defaultTest='suite')154 except Exception as e:155 print('Error: %s' % e)
modified:Makefile+1 added-1 removed
1test:2 python setup.py test2 python run-tests.py34develop:5 pip install --editable .6
15 unmodified lines
modified:MANIFEST.in+1 added-1 removed
1include MANIFEST.in Makefile CHANGES LICENSE AUTHORS1include MANIFEST.in Makefile CHANGES LICENSE AUTHORS run-tests.py2recursive-include docs *3recursive-include custom_fixers *4recursive-include ext *5recursive-include artwork *
7 unmodified lines
added:run-tests.py+5 added
1#!/usr/bin/env python2import sys, os3sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))4from jinja2.testsuite import main5main()
modified:tox.ini+1 added-1 removed
1[tox]2envlist = py26, py27, pypy, py3334[testenv]5commands = python setup.py test5commands = python run-tests.py