Ticket #8268: admin_scripts_jythonpath.diff

File admin_scripts_jythonpath.diff, 3.3 KB (added by Leo Soto M., 16 years ago)

slightly more invasive fix, gets rid of _sys_executable()

  • tests/regressiontests/admin_scripts/tests.py

    diff -r d49003a461ad tests/regressiontests/admin_scripts/tests.py
    a b  
    4242        test_dir = os.path.dirname(os.path.dirname(__file__))
    4343        full_name = os.path.join(test_dir, filename)
    4444        os.remove(full_name)
    45        
     45
    4646        # Also try to remove the compiled file; if it exists, it could
    4747        # mess up later tests that depend upon the .py file not existing
    4848        try:
     
    5454                os.remove(full_name + 'c')
    5555        except OSError:
    5656            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
    6957
    7058    def _ext_backend_path(self):
    7159        """
     
    8674
    8775        # Remember the old environment
    8876        old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
    89         old_python_path = os.environ.get('PYTHONPATH', None)
     77        if sys.platform.startswith('java'):
     78            python_path_var_name = 'JYTHONPATH'
     79        else:
     80            python_path_var_name = 'PYTHONPATH'
     81
     82        old_python_path = os.environ.get(python_path_var_name, None)
    9083        old_cwd = os.getcwd()
    9184
    9285        # Set the test environment
     
    9790        python_path = [test_dir, base_dir]
    9891        if ext_backend_base_dir:
    9992            python_path.append(ext_backend_base_dir)
    100         os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
    101 
     93        os.environ[python_path_var_name] = os.pathsep.join(python_path)
    10294
    10395        # Build the command line
    104         cmd = '%s "%s"' % (self._sys_executable(), script)
     96        cmd = '%s "%s"' % (sys.executable, script)
    10597        cmd += ''.join([' %s' % arg for arg in args])
    10698
    10799        # Move to the test directory and run
     
    118110        if old_django_settings_module:
    119111            os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
    120112        if old_python_path:
    121             os.environ['PYTHONPATH'] = old_python_path
     113            os.environ[python_path_var_name] = old_python_path
    122114        # Move back to the old working directory
    123115        os.chdir(old_cwd)
    124116
     
    425417        self.assertNoOutput(out)
    426418        self.assertOutput(err, "Could not import settings 'bad_settings'")
    427419
    428     def test_custom_command(self): 
     420    def test_custom_command(self):
    429421        "alternate: django-admin can't execute user commands unless settings are provided"
    430422        args = ['noargs_command']
    431423        out, err = self.run_django_admin(args)
     
    495487        self.assertNoOutput(out)
    496488        self.assertOutput(err, "Could not import settings 'bad_settings'")
    497489
    498     def test_custom_command(self): 
     490    def test_custom_command(self):
    499491        "alternate: django-admin can't execute user commands unless settings are provided"
    500492        args = ['noargs_command']
    501493        out, err = self.run_django_admin(args)
Back to Top