Ticket #8047: 8047_admin_scripts_tests_on_jython.4.diff

File 8047_admin_scripts_tests_on_jython.4.diff, 2.6 KB (added by Leo Soto M., 16 years ago)

updated to svn r8162

  • tests/regressiontests/admin_scripts/tests.py

    diff -r 184be4897104 -r 2bb0b29055aa tests/regressiontests/admin_scripts/tests.py
    a b  
    4545       
    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
     48        def try_remove(name):
     49            try:
    4850        try:
    4951            if sys.platform.startswith('java'):
    5052                # Jython produces module$py.class files
     
    5254            else:
    5355                # CPython produces module.pyc files
    5456                os.remove(full_name + 'c')
    55         except OSError:
    56             pass
     57            except OSError:
     58                pass
    5759       
    5860    def _sys_executable(self):
    5961        """
     
    6769        else:
    6870            return sys.executable
    6971
     72    def _ext_backend_path(self):
     73        """
     74        Returns the path for the external backend package, or None if no
     75        external backend is detected.
     76        """
     77        first_package_re = re.compile(r'(^[^\.]+)\.')
     78        result = first_package_re.findall(settings.DATABASE_ENGINE)
     79        if result:
     80            backend_pkg = __import__(result[0])
     81            backend_dir = os.path.dirname(backend_pkg.__file__)
     82            return os.path.dirname(backend_dir)
    7083    def run_test(self, script, args, settings_file=None, apps=None):
    7184        test_dir = os.path.dirname(os.path.dirname(__file__))
    7285        project_dir = os.path.dirname(test_dir)
    7386        base_dir = os.path.dirname(project_dir)
    74 
     87        ext_backend_base_dir = self._ext_backend_path()
    7588        # Remember the old environment
    7689        old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
    7790        old_python_path = os.environ.get('PYTHONPATH', None)
     
    8295            os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
    8396        elif 'DJANGO_SETTINGS_MODULE' in os.environ:
    8497            del os.environ['DJANGO_SETTINGS_MODULE']
    85            
    86         if old_python_path:
    87             os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path])
    88         else:
    89             os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir])
     98        python_path = [test_dir, base_dir]
     99        if ext_backend_base_dir:
     100            python_path.append(ext_backend_base_dir)
     101        os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
     102
    90103
    91104        # Build the command line
    92105        cmd = '%s "%s"' % (self._sys_executable(), script)
Back to Top