Django

Code

Changeset 8158

Show
Ignore:
Timestamp:
07/31/08 03:32:19 (4 months ago)
Author:
russellm
Message:

Refs #8047 -- Removed some CPython specific parts of the admin scripts tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/admin_scripts/tests.py

    r8149 r8158  
    88import shutil 
    99import sys 
     10import re 
    1011 
    1112from django import conf, bin, get_version 
     
    4041    def remove_settings(self, filename): 
    4142        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 
    4447        # mess up later tests that depend upon the .py file not existing 
    4548        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') 
    4755        except OSError: 
    4856            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 
    4969 
    5070    def run_test(self, script, args, settings_file=None, apps=None): 
     
    5272        project_dir = os.path.dirname(test_dir) 
    5373        base_dir = os.path.dirname(project_dir) 
    54  
    55         # Build the command line 
    56         cmd = '%s "%s"' % (sys.executable, script) 
    57         cmd += ''.join([' %s' % arg for arg in args]) 
    5874 
    5975        # Remember the old environment 
     
    6783        elif 'DJANGO_SETTINGS_MODULE' in os.environ: 
    6884            del os.environ['DJANGO_SETTINGS_MODULE'] 
    69  
     85             
    7086        if old_python_path: 
    7187            os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path]) 
    7288        else: 
    7389            os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir]) 
     90 
     91        # Build the command line 
     92        cmd = '%s "%s"' % (self._sys_executable(), script) 
     93        cmd += ''.join([' %s' % arg for arg in args]) 
    7494 
    7595        # Move to the test directory and run 
     
    83103        if old_python_path: 
    84104            os.environ['PYTHONPATH'] = old_python_path 
    85  
    86105        # Move back to the old working directory 
    87106        os.chdir(old_cwd) 
     
    824843        self.assertNoOutput(err) 
    825844        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)]") 
    827847        self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'") 
    828848        self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))