diff -r 4fbc3b1ae323 tests/regressiontests/admin_scripts/tests.py
a
|
b
|
|
7 | 7 | import unittest |
8 | 8 | import shutil |
9 | 9 | import sys |
| 10 | import re |
10 | 11 | |
11 | 12 | from django import conf, bin, get_version |
12 | 13 | from django.conf import settings |
… |
… |
|
40 | 41 | def remove_settings(self, filename): |
41 | 42 | test_dir = os.path.dirname(os.path.dirname(__file__)) |
42 | 43 | os.remove(os.path.join(test_dir, filename)) |
43 | | # Also try to remove the pyc file; if it exists, it could |
| 44 | # Also try to remove the compiled file; if it exists, it could |
44 | 45 | # mess up later tests that depend upon the .py file not existing |
45 | | try: |
46 | | os.remove(os.path.join(test_dir, filename + 'c')) |
47 | | except OSError: |
48 | | pass |
| 46 | def try_remove(name): |
| 47 | try: |
| 48 | os.remove(os.path.join(test_dir, name)) |
| 49 | except OSError: |
| 50 | pass |
| 51 | # Remove *.pyc |
| 52 | try_remove(filename + 'c') |
| 53 | # Remove *$py.class (for Jython) |
| 54 | try_remove(re.sub(r'\.py$', '$py.class', filename)) |
| 55 | |
| 56 | def _sys_executable(self, python_path): |
| 57 | """ |
| 58 | Returns the command line needed to run a python interpreter, with the specified PYTHONPATH. |
| 59 | """ |
| 60 | if sys.platform.startswith('java'): |
| 61 | return "%s -J-Dpython.path=%s" % \ |
| 62 | (sys.executable, python_path) |
| 63 | else: |
| 64 | return "PYTHONPATH=%s %s" % (python_path, sys.executable) |
49 | 65 | |
50 | 66 | def run_test(self, script, args, settings_file=None, apps=None): |
51 | 67 | test_dir = os.path.dirname(os.path.dirname(__file__)) |
52 | 68 | project_dir = os.path.dirname(test_dir) |
53 | 69 | base_dir = os.path.dirname(project_dir) |
54 | 70 | |
55 | | # Build the command line |
56 | | cmd = '%s "%s"' % (sys.executable, script) |
57 | | cmd += ''.join([' %s' % arg for arg in args]) |
58 | | |
59 | 71 | # Remember the old environment |
60 | 72 | old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None) |
61 | | old_python_path = os.environ.get('PYTHONPATH', None) |
62 | 73 | old_cwd = os.getcwd() |
63 | 74 | |
64 | 75 | # Set the test environment |
… |
… |
|
66 | 77 | os.environ['DJANGO_SETTINGS_MODULE'] = settings_file |
67 | 78 | elif 'DJANGO_SETTINGS_MODULE' in os.environ: |
68 | 79 | del os.environ['DJANGO_SETTINGS_MODULE'] |
| 80 | python_path = os.pathsep.join([test_dir, base_dir] + sys.path) |
69 | 81 | |
70 | | if old_python_path: |
71 | | os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path]) |
72 | | else: |
73 | | os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir]) |
| 82 | # Build the command line |
| 83 | cmd = '%s "%s"' % (self._sys_executable(python_path), script) |
| 84 | cmd += ''.join([' %s' % arg for arg in args]) |
74 | 85 | |
75 | 86 | # Move to the test directory and run |
76 | 87 | os.chdir(test_dir) |
… |
… |
|
80 | 91 | # Restore the old environment |
81 | 92 | if old_django_settings_module: |
82 | 93 | os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module |
83 | | if old_python_path: |
84 | | os.environ['PYTHONPATH'] = old_python_path |
85 | 94 | |
86 | 95 | # Move back to the old working directory |
87 | 96 | os.chdir(old_cwd) |
… |
… |
|
823 | 832 | out, err = self.run_manage(args) |
824 | 833 | self.assertNoOutput(err) |
825 | 834 | self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'") |
826 | | self.assertOutput(out, os.sep.join(['django','contrib','auth','models.pyc']) + "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]") |
| 835 | self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) |
827 | 836 | self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'") |
828 | 837 | self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py'])) |
829 | 838 | self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]") |