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
|
@ -55,18 +55,6 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
Returns the path for the external backend package, or None if no
|
Returns the path for the external backend package, or None if no
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue