Changeset 8158
- Timestamp:
- 07/31/08 03:32:19 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/regressiontests/admin_scripts/tests.py
r8149 r8158 8 8 import shutil 9 9 import sys 10 import re 10 11 11 12 from django import conf, bin, get_version … … 40 41 def remove_settings(self, filename): 41 42 test_dir = os.path.dirname(os.path.dirname(__file__)) 42 os.remove(os.path.join(test_dir, filename)) 43 # Also try to remove the pyc file; if it exists, it could 43 full_name = os.path.join(test_dir, filename) 44 os.remove(full_name) 45 46 # Also try to remove the compiled file; if it exists, it could 44 47 # mess up later tests that depend upon the .py file not existing 45 48 try: 46 os.remove(os.path.join(test_dir, filename + 'c')) 49 if sys.platform.startswith('java'): 50 # Jython produces module$py.class files 51 os.remove(re.sub(r'\.py$', '$py.class', fullname)) 52 else: 53 # CPython produces module.pyc files 54 os.remove(full_name + 'c') 47 55 except OSError: 48 56 pass 57 58 def _sys_executable(self): 59 """ 60 Returns the command line needed to run a python interpreter, including 61 the options for setting sys.path on Jython, which doesn't recognize 62 PYTHONPATH. 63 """ 64 if sys.platform.startswith('java'): 65 return "%s -J-Dpython.path=%s" % \ 66 (sys.executable, os.environ['PYTHONPATH']) 67 else: 68 return sys.executable 49 69 50 70 def run_test(self, script, args, settings_file=None, apps=None): … … 52 72 project_dir = os.path.dirname(test_dir) 53 73 base_dir = os.path.dirname(project_dir) 54 55 # Build the command line56 cmd = '%s "%s"' % (sys.executable, script)57 cmd += ''.join([' %s' % arg for arg in args])58 74 59 75 # Remember the old environment … … 67 83 elif 'DJANGO_SETTINGS_MODULE' in os.environ: 68 84 del os.environ['DJANGO_SETTINGS_MODULE'] 69 85 70 86 if old_python_path: 71 87 os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path]) 72 88 else: 73 89 os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir]) 90 91 # Build the command line 92 cmd = '%s "%s"' % (self._sys_executable(), script) 93 cmd += ''.join([' %s' % arg for arg in args]) 74 94 75 95 # Move to the test directory and run … … 83 103 if old_python_path: 84 104 os.environ['PYTHONPATH'] = old_python_path 85 86 105 # Move back to the old working directory 87 106 os.chdir(old_cwd) … … 824 843 self.assertNoOutput(err) 825 844 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)]") 845 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) 846 self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]") 827 847 self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'") 828 848 self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))
