Fixed #8268: Modified admin scripts tests to use JYTHONPATH when appropriate. Thanks to leosoto for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2b82a3bcfc
commit
fc2c03b55c
|
@ -42,7 +42,7 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
test_dir = os.path.dirname(os.path.dirname(__file__))
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
full_name = os.path.join(test_dir, filename)
|
full_name = os.path.join(test_dir, filename)
|
||||||
os.remove(full_name)
|
os.remove(full_name)
|
||||||
|
|
||||||
# Also try to remove the compiled file; if it exists, it could
|
# 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:
|
||||||
|
@ -54,18 +54,6 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
os.remove(full_name + 'c')
|
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 _ext_backend_path(self):
|
def _ext_backend_path(self):
|
||||||
"""
|
"""
|
||||||
|
@ -78,6 +66,7 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
backend_pkg = __import__(result[0])
|
backend_pkg = __import__(result[0])
|
||||||
backend_dir = os.path.dirname(backend_pkg.__file__)
|
backend_dir = os.path.dirname(backend_pkg.__file__)
|
||||||
return os.path.dirname(backend_dir)
|
return os.path.dirname(backend_dir)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -86,7 +75,12 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# 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)
|
if sys.platform.startswith('java'):
|
||||||
|
python_path_var_name = 'JYTHONPATH'
|
||||||
|
else:
|
||||||
|
python_path_var_name = 'PYTHONPATH'
|
||||||
|
|
||||||
|
old_python_path = os.environ.get(python_path_var_name, None)
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
|
|
||||||
# Set the test environment
|
# Set the test environment
|
||||||
|
@ -97,11 +91,10 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
python_path = [test_dir, base_dir]
|
python_path = [test_dir, base_dir]
|
||||||
if ext_backend_base_dir:
|
if ext_backend_base_dir:
|
||||||
python_path.append(ext_backend_base_dir)
|
python_path.append(ext_backend_base_dir)
|
||||||
os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
|
os.environ[python_path_var_name] = os.pathsep.join(python_path)
|
||||||
|
|
||||||
|
|
||||||
# Build the command line
|
# Build the command line
|
||||||
cmd = '%s "%s"' % (self._sys_executable(), script)
|
cmd = '%s "%s"' % (sys.executable, script)
|
||||||
cmd += ''.join([' %s' % arg for arg in args])
|
cmd += ''.join([' %s' % arg for arg in args])
|
||||||
|
|
||||||
# Move to the test directory and run
|
# Move to the test directory and run
|
||||||
|
@ -118,7 +111,7 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
if old_django_settings_module:
|
if old_django_settings_module:
|
||||||
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[python_path_var_name] = 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)
|
||||||
|
|
||||||
|
@ -425,7 +418,7 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
||||||
|
|
||||||
def test_custom_command(self):
|
def test_custom_command(self):
|
||||||
"alternate: django-admin can't execute user commands unless settings are provided"
|
"alternate: django-admin can't execute user commands unless settings are provided"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
|
@ -495,7 +488,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
||||||
|
|
||||||
def test_custom_command(self):
|
def test_custom_command(self):
|
||||||
"alternate: django-admin can't execute user commands unless settings are provided"
|
"alternate: django-admin can't execute user commands unless settings are provided"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
|
|
Loading…
Reference in New Issue