Refs #8047 -- Removed some CPython specific parts of the admin scripts tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8158 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2008-07-31 08:32:19 +00:00
parent 7a87f5aeab
commit 9ea8184da8
1 changed files with 30 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import os
import unittest import unittest
import shutil import shutil
import sys import sys
import re
from django import conf, bin, get_version from django import conf, bin, get_version
from django.conf import settings from django.conf import settings
@ -39,23 +40,38 @@ class AdminScriptTestCase(unittest.TestCase):
def remove_settings(self, filename): def remove_settings(self, filename):
test_dir = os.path.dirname(os.path.dirname(__file__)) test_dir = os.path.dirname(os.path.dirname(__file__))
os.remove(os.path.join(test_dir, filename)) full_name = os.path.join(test_dir, filename)
# Also try to remove the pyc file; if it exists, it could os.remove(full_name)
# Also try to remove the compiled file; if it exists, it could
# mess up later tests that depend upon the .py file not existing # mess up later tests that depend upon the .py file not existing
try: try:
os.remove(os.path.join(test_dir, filename + 'c')) if sys.platform.startswith('java'):
# Jython produces module$py.class files
os.remove(re.sub(r'\.py$', '$py.class', fullname))
else:
# CPython produces module.pyc files
os.remove(full_name + 'c')
except OSError: except OSError:
pass pass
def _sys_executable(self):
"""
Returns the command line needed to run a python interpreter, including
the options for setting sys.path on Jython, which doesn't recognize
PYTHONPATH.
"""
if sys.platform.startswith('java'):
return "%s -J-Dpython.path=%s" % \
(sys.executable, os.environ['PYTHONPATH'])
else:
return sys.executable
def run_test(self, script, args, settings_file=None, apps=None): def run_test(self, script, args, settings_file=None, apps=None):
test_dir = os.path.dirname(os.path.dirname(__file__)) test_dir = os.path.dirname(os.path.dirname(__file__))
project_dir = os.path.dirname(test_dir) project_dir = os.path.dirname(test_dir)
base_dir = os.path.dirname(project_dir) base_dir = os.path.dirname(project_dir)
# Build the command line
cmd = '%s "%s"' % (sys.executable, script)
cmd += ''.join([' %s' % arg for arg in args])
# Remember the old environment # Remember the old environment
old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None) old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
old_python_path = os.environ.get('PYTHONPATH', None) old_python_path = os.environ.get('PYTHONPATH', None)
@ -66,12 +82,16 @@ class AdminScriptTestCase(unittest.TestCase):
os.environ['DJANGO_SETTINGS_MODULE'] = settings_file os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
elif 'DJANGO_SETTINGS_MODULE' in os.environ: elif 'DJANGO_SETTINGS_MODULE' in os.environ:
del os.environ['DJANGO_SETTINGS_MODULE'] del os.environ['DJANGO_SETTINGS_MODULE']
if old_python_path: if old_python_path:
os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path]) os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path])
else: else:
os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir]) os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir])
# Build the command line
cmd = '%s "%s"' % (self._sys_executable(), script)
cmd += ''.join([' %s' % arg for arg in args])
# Move to the test directory and run # Move to the test directory and run
os.chdir(test_dir) os.chdir(test_dir)
stdin, stdout, stderr = os.popen3(cmd) stdin, stdout, stderr = os.popen3(cmd)
@ -82,7 +102,6 @@ class AdminScriptTestCase(unittest.TestCase):
os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
if old_python_path: if old_python_path:
os.environ['PYTHONPATH'] = old_python_path os.environ['PYTHONPATH'] = old_python_path
# Move back to the old working directory # Move back to the old working directory
os.chdir(old_cwd) os.chdir(old_cwd)
@ -823,7 +842,8 @@ class CommandTypes(AdminScriptTestCase):
out, err = self.run_manage(args) out, err = self.run_manage(args)
self.assertNoOutput(err) self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'") self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
self.assertOutput(out, os.sep.join(['django','contrib','auth','models.pyc']) + "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]") self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))
self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'") self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")
self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py'])) self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))
self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]") self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")