Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refs #8047 -- Removed some CPython specific parts of the admin script…

…s tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8158 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9ea8184da83954b47221dfdcae5928626b7a9f02 1 parent 7a87f5a
Russell Keith-Magee authored
40  tests/regressiontests/admin_scripts/tests.py
@@ -7,6 +7,7 @@
7 7
 import unittest
8 8
 import shutil
9 9
 import sys
  10
+import re
10 11
 
11 12
 from django import conf, bin, get_version
12 13
 from django.conf import settings
@@ -39,23 +40,38 @@ def write_settings(self, filename, apps=None):
39 40
 
40 41
     def remove_settings(self, filename):
41 42
         test_dir = os.path.dirname(os.path.dirname(__file__))
42  
-        os.remove(os.path.join(test_dir, filename))
43  
-        # Also try to remove the pyc file; if it exists, it could
  43
+        full_name = os.path.join(test_dir, filename)
  44
+        os.remove(full_name)
  45
+        
  46
+        # Also try to remove the compiled file; if it exists, it could
44 47
         # mess up later tests that depend upon the .py file not existing
45 48
         try:
46  
-            os.remove(os.path.join(test_dir, filename + 'c'))
  49
+            if sys.platform.startswith('java'):
  50
+                # Jython produces module$py.class files
  51
+                os.remove(re.sub(r'\.py$', '$py.class', fullname))
  52
+            else:
  53
+                # CPython produces module.pyc files
  54
+                os.remove(full_name + 'c')
47 55
         except OSError:
48 56
             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
49 69
 
50 70
     def run_test(self, script, args, settings_file=None, apps=None):
51 71
         test_dir = os.path.dirname(os.path.dirname(__file__))
52 72
         project_dir = os.path.dirname(test_dir)
53 73
         base_dir = os.path.dirname(project_dir)
54 74
 
55  
-        # Build the command line
56  
-        cmd = '%s "%s"' % (sys.executable, script)
57  
-        cmd += ''.join([' %s' % arg for arg in args])
58  
-
59 75
         # Remember the old environment
60 76
         old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
61 77
         old_python_path = os.environ.get('PYTHONPATH', None)
@@ -66,12 +82,16 @@ def run_test(self, script, args, settings_file=None, apps=None):
66 82
             os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
67 83
         elif 'DJANGO_SETTINGS_MODULE' in os.environ:
68 84
             del os.environ['DJANGO_SETTINGS_MODULE']
69  
-
  85
+            
70 86
         if old_python_path:
71 87
             os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path])
72 88
         else:
73 89
             os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir])
74 90
 
  91
+        # Build the command line
  92
+        cmd = '%s "%s"' % (self._sys_executable(), script)
  93
+        cmd += ''.join([' %s' % arg for arg in args])
  94
+
75 95
         # Move to the test directory and run
76 96
         os.chdir(test_dir)
77 97
         stdin, stdout, stderr = os.popen3(cmd)
@@ -82,7 +102,6 @@ def run_test(self, script, args, settings_file=None, apps=None):
82 102
             os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
83 103
         if old_python_path:
84 104
             os.environ['PYTHONPATH'] = old_python_path
85  
-
86 105
         # Move back to the old working directory
87 106
         os.chdir(old_cwd)
88 107
 
@@ -823,7 +842,8 @@ def test_app_command_multiple_apps(self):
823 842
         out, err = self.run_manage(args)
824 843
         self.assertNoOutput(err)
825 844
         self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
826  
-        self.assertOutput(out, os.sep.join(['django','contrib','auth','models.pyc']) + "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
  845
+        self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))
  846
+        self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
827 847
         self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")
828 848
         self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))
829 849
         self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")

0 notes on commit 9ea8184

Please sign in to comment.
Something went wrong with that request. Please try again.