Ticket #6364: patch_django_6364.diff
File patch_django_6364.diff, 3.2 KB (added by , 17 years ago) |
---|
-
django/test/simple.py
1 import os 1 2 import unittest 2 3 from django.conf import settings 3 4 from django.db.models import get_app, get_apps … … 8 9 9 10 # The module name for tests outside models.py 10 11 TEST_MODULE = 'tests' 11 12 DOCTEST_EXTENSION = '.txt' 13 12 14 doctestOutputChecker = OutputChecker() 13 15 14 16 def get_tests(app_module): … … 71 73 except ValueError: 72 74 # No doc tests in tests.py 73 75 pass 76 try: 77 # Add doctests if there are .txt in tests' module 78 doctests_dir = test_module.__path__[0] 79 doctest_files = [os.path.join(doctests_dir, doc) \ 80 for doc in os.listdir(doctests_dir) \ 81 if doc.endswith(DOCTEST_EXTENSION)] 82 for doctest_file in doctest_files: 83 suite.addTest(doctest.DocFileSuite(doctest_file, 84 checker=doctestOutputChecker, 85 runner=DocTestRunner, 86 module_relative=False)) 87 except: 88 # TODO 89 pass 74 90 return suite 75 91 76 92 def build_test(label): 77 93 """Construct a test case a test with the specified label. Label should 78 94 be of the form model.TestClass or model.TestClass.test_method. Returns 79 95 an instantiated test or test suite corresponding to the label provided. 80 81 96 """ 82 97 parts = label.split('.') 83 98 if len(parts) < 2 or len(parts) > 3: … … 100 115 else: # label is app.TestClass.test_method 101 116 return TestClass(parts[2]) 102 117 118 def build_doctest(label): 119 """Construct a test case a test with the specified label. Label should 120 be of the form model.doctest_filename. Returns an instantiated test or 121 test suite corresponding to the label provided. 122 """ 123 import os 124 parts = label.split('.') 125 if len(parts) != 2: 126 raise ValueError("TODO") 127 app = get_app(parts[0]) 128 test_filename = parts[1] + DOCTEST_EXTENSION 129 test_file = os.path.join(get_tests(app).__path__[0], test_filename) 130 try: 131 return doctest.DocFileSuite(test_file, 132 checker=doctestOutputChecker, 133 runner=DocTestRunner, 134 module_relative=False) 135 except IOError: 136 raise ValueError("File '%s' does not exist" % test_file) 137 103 138 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): 104 139 """ 105 140 Run the unit tests for all the test labels in the provided list. … … 127 162 if test_labels: 128 163 for label in test_labels: 129 164 if '.' in label: 130 suite.addTest(build_test(label)) 165 try: 166 suite.addTest(build_test(label)) 167 except ValueError: 168 suite.addTest(build_doctest(label)) 131 169 else: 132 170 app = get_app(label) 133 171 suite.addTest(build_suite(app))