Changeset 2310
- Timestamp:
- 02/16/06 08:07:23 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/core/management.py (modified) (5 diffs)
- django/branches/magic-removal/tests/modeltests/invalid_models (added)
- django/branches/magic-removal/tests/modeltests/invalid_models/__init__.py (added)
- django/branches/magic-removal/tests/modeltests/invalid_models/models.py (added)
- django/branches/magic-removal/tests/runtests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/core/management.py
r2296 r2310 525 525 # First, try validating the models. 526 526 s = StringIO() 527 num_errors = get_validation_errors(s )527 num_errors = get_validation_errors(s, app) 528 528 if num_errors: 529 529 sys.stderr.write("Error: %s couldn't be installed, because there were errors in your model:\n" % app_name) … … 560 560 # First, try validating the models. 561 561 s = StringIO() 562 num_errors = get_validation_errors(s )562 num_errors = get_validation_errors(s, app) 563 563 if num_errors: 564 564 sys.stderr.write("Error: %s couldn't be installed, because there were errors in your model:\n" % app_name) … … 820 820 self.outfile.write("%s.%s: %s\n" % (opts.app_label, opts.module_name, error)) 821 821 822 def get_validation_errors(outfile): 823 "Validates all installed models. Writes errors, if any, to outfile. Returns number of errors." 822 def get_validation_errors(outfile, app=None): 823 """ 824 Validates all models that are part of the specified app. If no app name is provided, 825 validates all models of all installed apps. Writes errors, if any, to outfile. 826 Returns number of errors. 827 """ 824 828 from django.db import models 825 829 from django.db.models.fields.related import RelatedObject 826 830 827 831 e = ModelErrorCollection(outfile) 828 for cls in models.get_models( ):832 for cls in models.get_models(app): 829 833 opts = cls._meta 830 834 … … 865 869 if f.rel: 866 870 rel_opts = f.rel.to._meta 871 if f.rel.to not in models.get_models(): 872 e.add(opts, "'%s' field: relates to uninstalled model %s" % (f.name, rel_opts.object_name)) 873 867 874 rel_name = RelatedObject(f.rel.to, cls, f).OLD_get_accessor_name() 868 875 if rel_name in [r.name for r in rel_opts.fields]: … … 880 887 if f.rel: 881 888 rel_opts = f.rel.to._meta 889 if f.rel.to not in models.get_models(): 890 e.add(opts, "'%s' field: has m2m relation with uninstalled model %s" % (f.name, rel_opts.object_name)) 891 882 892 rel_name = RelatedObject(f.rel.to, cls, f).OLD_get_accessor_name() 883 893 if rel_name in [r.name for r in rel_opts.fields]: django/branches/magic-removal/tests/runtests.py
r2279 r2310 83 83 # Determine which models we're going to test. 84 84 test_models = get_test_models() 85 if 'othertests' in self.which_tests: 86 self.which_tests.remove('othertests') 87 run_othertests = True 88 if not self.which_tests: 89 test_models = [] 90 else: 91 run_othertests = not self.which_tests 92 85 93 if self.which_tests: 86 94 # Only run the specified tests. … … 139 147 log_error(model_name, "Error while importing", ''.join(traceback.format_exception(*sys.exc_info())[1:])) 140 148 continue 141 self.output(1, "%s model: Installing" % model_name) 142 management.install(mod) 143 144 # Run the API tests. 145 p = doctest.DocTestParser() 146 test_namespace = dict([(m._meta.object_name, m) \ 147 for m in django.db.models.get_models(mod)]) 148 dtest = p.get_doctest(mod.API_TESTS, test_namespace, model_name, None, None) 149 # Manually set verbose=False, because "-v" command-line parameter 150 # has side effects on doctest TestRunner class. 151 runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 152 self.output(1, "%s model: Running tests" % model_name) 153 runner.run(dtest, clear_globs=True, out=sys.stdout.write) 154 155 if not self.which_tests: 149 150 if not getattr(mod, 'error_log', None): 151 # Model is not marked as an invalid model 152 self.output(1, "%s model: Installing" % model_name) 153 management.install(mod) 154 155 # Run the API tests. 156 p = doctest.DocTestParser() 157 test_namespace = dict([(m._meta.object_name, m) \ 158 for m in django.db.models.get_models(mod)]) 159 dtest = p.get_doctest(mod.API_TESTS, test_namespace, model_name, None, None) 160 # Manually set verbose=False, because "-v" command-line parameter 161 # has side effects on doctest TestRunner class. 162 runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 163 self.output(1, "%s model: Running tests" % model_name) 164 runner.run(dtest, clear_globs=True, out=sys.stdout.write) 165 else: 166 # Check that model known to be invalid is invalid for the right reasons. 167 self.output(1, "%s model: Validating" % model_name) 168 169 from cStringIO import StringIO 170 s = StringIO() 171 count = management.get_validation_errors(s, mod) 172 s.seek(0) 173 error_log = s.read() 174 expected = len(mod.error_log.split('\n')) - 1 175 if error_log != mod.error_log: 176 log_error(model_name, 177 "Validator found %d validation errors, %d expected" % (count, expected), 178 "Expected errors:\n%s\n\nActual errors:\n%s" % (mod.error_log, error_log)) 179 180 181 if run_othertests: 156 182 # Run the non-model tests in the other tests dir 157 183 self.output(1, "Running other tests")
