Commit 7f264e02 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Fixed #20680 -- Deprecated django.utils.unittest.

Refs #19204.
parent 88de53d4
Loading
Loading
Loading
Loading
+4 −75
Original line number Diff line number Diff line
"""
unittest2
import warnings

unittest2 is a backport of the new features added to the unittest testing
framework in Python 2.7. It is tested to run on Python 2.4 - 2.6.

To use unittest2 instead of unittest simply replace ``import unittest`` with
``import unittest2``.


Copyright (c) 1999-2003 Steve Purcell
Copyright (c) 2003-2010 Python Software Foundation
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
"""

import sys

# Django hackery to load the appropriate version of unittest
warnings.warn("django.utils.unittest will be removed in Django 1.9.",
    PendingDeprecationWarning)

try:
    # check the system path first
    from unittest2 import *
except ImportError:
    if sys.version_info >= (2,7):
        # unittest2 features are native in Python 2.7
    from unittest import *
    else:
        # otherwise use our bundled version
        __all__ = ['TestResult', 'TestCase', 'TestSuite',
                   'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
                   'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
                   'expectedFailure', 'TextTestResult', '__version__', 'collector']

        __version__ = '0.5.1'

        # Expose obsolete functions for backwards compatibility
        __all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])


        from django.utils.unittest.collector import collector
        from django.utils.unittest.result import TestResult
        from django.utils.unittest.case import \
            TestCase, FunctionTestCase, SkipTest, skip, skipIf,\
            skipUnless, expectedFailure

        from django.utils.unittest.suite import BaseTestSuite, TestSuite
        from django.utils.unittest.loader import \
            TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,\
            findTestCases

        from django.utils.unittest.main import TestProgram, main, main_
        from django.utils.unittest.runner import TextTestRunner, TextTestResult

        try:
            from django.utils.unittest.signals import\
                installHandler, registerResult, removeResult, removeHandler
        except ImportError:
            # Compatibility with platforms that don't have the signal module
            pass
        else:
            __all__.extend(['installHandler', 'registerResult', 'removeResult',
                            'removeHandler'])

        # deprecated
        _TextTestResult = TextTestResult

        __unittest = True

django/utils/unittest/__main__.py

deleted100644 → 0
+0 −10
Original line number Diff line number Diff line
"""Main entry point"""

import sys
if sys.argv[0].endswith("__main__.py"):
    sys.argv[0] = "unittest2"

__unittest = True

from django.utils.unittest.main import main_
main_()

django/utils/unittest/case.py

deleted100644 → 0
+0 −1076

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −9
Original line number Diff line number Diff line
import os
import sys
from django.utils.unittest.loader import defaultTestLoader

def collector():
    # import __main__ triggers code re-execution
    __main__ = sys.modules['__main__']
    setupDir = os.path.abspath(os.path.dirname(__main__.__file__))
    return defaultTestLoader.discover(setupDir)
+0 −64
Original line number Diff line number Diff line
import os
import sys

try:
    from functools import wraps
except ImportError:
    # only needed for Python 2.4
    def wraps(_):
        def _wraps(func):
            return func
        return _wraps

__unittest = True

def _relpath_nt(path, start=os.path.curdir):
    """Return a relative version of a path"""

    if not path:
        raise ValueError("no path specified")
    start_list = os.path.abspath(start).split(os.path.sep)
    path_list = os.path.abspath(path).split(os.path.sep)
    if start_list[0].lower() != path_list[0].lower():
        unc_path, rest = os.path.splitunc(path)
        unc_start, rest = os.path.splitunc(start)
        if bool(unc_path) ^ bool(unc_start):
            raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                % (path, start))
        else:
            raise ValueError("path is on drive %s, start on drive %s"
                                                % (path_list[0], start_list[0]))
    # Work out how much of the filepath is shared by start and path.
    for i in range(min(len(start_list), len(path_list))):
        if start_list[i].lower() != path_list[i].lower():
            break
    else:
        i += 1

    rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
    if not rel_list:
        return os.path.curdir
    return os.path.join(*rel_list)

# default to posixpath definition
def _relpath_posix(path, start=os.path.curdir):
    """Return a relative version of a path"""

    if not path:
        raise ValueError("no path specified")

    start_list = os.path.abspath(start).split(os.path.sep)
    path_list = os.path.abspath(path).split(os.path.sep)

    # Work out how much of the filepath is shared by start and path.
    i = len(os.path.commonprefix([start_list, path_list]))

    rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
    if not rel_list:
        return os.path.curdir
    return os.path.join(*rel_list)

if os.path is sys.modules.get('ntpath'):
    relpath = _relpath_nt
else:
    relpath = _relpath_posix
Loading