Code

Ticket #8268: admin_scripts_jythonpath.diff

File admin_scripts_jythonpath.diff, 3.3 KB (added by leosoto, 6 years ago)

slightly more invasive fix, gets rid of _sys_executable()

Line 
1diff -r d49003a461ad tests/regressiontests/admin_scripts/tests.py
2--- a/tests/regressiontests/admin_scripts/tests.py      Fri Aug 15 14:15:19 2008 -0400
3+++ b/tests/regressiontests/admin_scripts/tests.py      Fri Aug 15 21:10:24 2008 -0400
4@@ -42,7 +42,7 @@
5         test_dir = os.path.dirname(os.path.dirname(__file__))
6         full_name = os.path.join(test_dir, filename)
7         os.remove(full_name)
8-       
9+
10         # Also try to remove the compiled file; if it exists, it could
11         # mess up later tests that depend upon the .py file not existing
12         try:
13@@ -54,18 +54,6 @@
14                 os.remove(full_name + 'c')
15         except OSError:
16             pass
17-       
18-    def _sys_executable(self):
19-        """
20-        Returns the command line needed to run a python interpreter, including
21-        the options for setting sys.path on Jython, which doesn't recognize
22-        PYTHONPATH.
23-        """
24-        if sys.platform.startswith('java'):
25-            return "%s -J-Dpython.path=%s" % \
26-                   (sys.executable, os.environ['PYTHONPATH'])
27-        else:
28-            return sys.executable
29 
30     def _ext_backend_path(self):
31         """
32@@ -86,7 +74,12 @@
33 
34         # Remember the old environment
35         old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
36-        old_python_path = os.environ.get('PYTHONPATH', None)
37+        if sys.platform.startswith('java'):
38+            python_path_var_name = 'JYTHONPATH'
39+        else:
40+            python_path_var_name = 'PYTHONPATH'
41+
42+        old_python_path = os.environ.get(python_path_var_name, None)
43         old_cwd = os.getcwd()
44 
45         # Set the test environment
46@@ -97,11 +90,10 @@
47         python_path = [test_dir, base_dir]
48         if ext_backend_base_dir:
49             python_path.append(ext_backend_base_dir)
50-        os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
51-
52+        os.environ[python_path_var_name] = os.pathsep.join(python_path)
53 
54         # Build the command line
55-        cmd = '%s "%s"' % (self._sys_executable(), script)
56+        cmd = '%s "%s"' % (sys.executable, script)
57         cmd += ''.join([' %s' % arg for arg in args])
58 
59         # Move to the test directory and run
60@@ -118,7 +110,7 @@
61         if old_django_settings_module:
62             os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
63         if old_python_path:
64-            os.environ['PYTHONPATH'] = old_python_path
65+            os.environ[python_path_var_name] = old_python_path
66         # Move back to the old working directory
67         os.chdir(old_cwd)
68 
69@@ -425,7 +417,7 @@
70         self.assertNoOutput(out)
71         self.assertOutput(err, "Could not import settings 'bad_settings'")
72 
73-    def test_custom_command(self):
74+    def test_custom_command(self):
75         "alternate: django-admin can't execute user commands unless settings are provided"
76         args = ['noargs_command']
77         out, err = self.run_django_admin(args)
78@@ -495,7 +487,7 @@
79         self.assertNoOutput(out)
80         self.assertOutput(err, "Could not import settings 'bad_settings'")
81 
82-    def test_custom_command(self):
83+    def test_custom_command(self):
84         "alternate: django-admin can't execute user commands unless settings are provided"
85         args = ['noargs_command']
86         out, err = self.run_django_admin(args)