Commit fc2c03b5 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #8268: Modified admin scripts tests to use JYTHONPATH when appropriate....

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
parent 2b82a3bc
Loading
Loading
Loading
Loading
+13 −20
Original line number Diff line number Diff line
@@ -55,18 +55,6 @@ class AdminScriptTestCase(unittest.TestCase):
        except OSError:
            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):
        """
        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_dir = os.path.dirname(backend_pkg.__file__)
            return os.path.dirname(backend_dir)

    def run_test(self, script, args, settings_file=None, apps=None):
        test_dir = os.path.dirname(os.path.dirname(__file__))
        project_dir = os.path.dirname(test_dir)
@@ -86,7 +75,12 @@ class AdminScriptTestCase(unittest.TestCase):

        # Remember the old environment
        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()

        # Set the test environment
@@ -97,11 +91,10 @@ class AdminScriptTestCase(unittest.TestCase):
        python_path = [test_dir, base_dir]
        if 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
        cmd = '%s "%s"' % (self._sys_executable(), script)
        cmd = '%s "%s"' % (sys.executable, script)
        cmd += ''.join([' %s' % arg for arg in args])

        # Move to the test directory and run
@@ -118,7 +111,7 @@ class AdminScriptTestCase(unittest.TestCase):
        if old_django_settings_module:
            os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
        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
        os.chdir(old_cwd)