django.utils.unittest.TestSuite

Here are the examples of the python api django.utils.unittest.TestSuite taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

34 Examples 7

Example 1

Project: GAE-Bulk-Mailer Source File: simple.py
Function: reorder_suite
def reorder_suite(suite, classes):
    """
    Reorders a test suite by test type.

    `classes` is a sequence of types

    All tests of type classes[0] are placed first, then tests of type
    classes[1], etc. Tests with no match in classes are placed last.
    """
    class_count = len(classes)
    bins = [unittest.TestSuite() for i in range(class_count+1)]
    partition_suite(suite, classes, bins)
    for i in range(class_count):
        bins[0].addTests(bins[i+1])
    return bins[0]

Example 2

Project: GAE-Bulk-Mailer Source File: simple.py
Function: build_suite
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if '.' in label:
                    suite.addTest(build_test(label))
                else:
                    app = get_app(label)
                    suite.addTest(build_suite(app))
        else:
            for app in get_apps():
                suite.addTest(build_suite(app))

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (unittest.TestCase,))

Example 3

Project: PyClassLessons Source File: simple.py
Function: build_suite
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if '.' in label:
                    suite.addTest(build_test(label))
                else:
                    app_config = apps.get_app_config(label)
                    suite.addTest(build_suite(app_config))
        else:
            for app_config in apps.get_app_configs():
                suite.addTest(build_suite(app_config))

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return runner.reorder_suite(suite, (unittest.TestCase,))

Example 4

Project: splunk-webframework Source File: __init__.py
Function: suite
def suite():
    "Builds a test suite for the GDAL tests."
    s = TestSuite()
    for test_suite in test_suites:
        s.addTest(test_suite)
    return s

Example 5

Project: splunk-webframework Source File: __init__.py
Function: suite
def suite():
    "Builds a test suite for the GEOS tests."
    s = TestSuite()
    for suite in test_suites:
        s.addTest(suite)
    return s

Example 6

Project: django-tastypie-mongoengine Source File: test_runner.py
Function: filter_suite
    def _filter_suite(self, suite):
        filters = getattr(settings, 'TEST_RUNNER_FILTER', None)

        if filters is None:
            # We do NOT filter if filters are not set
            return suite

        filtered = unittest.TestSuite()

        for test in suite:
            if isinstance(test, unittest.TestSuite):
                filtered.addTests(self._filter_suite(test))
            else:
                for f in filters:
                    if test.id().startswith(f):
                        filtered.addTest(test)

        return filtered

Example 7

Project: django-nonrel Source File: simple.py
Function: reorder_suite
def reorder_suite(suite, classes):
    """
    Reorders a test suite by test type.

    classes is a sequence of types

    All tests of type clases[0] are placed first, then tests of type classes[1], etc.
    Tests with no match in classes are placed last.
    """
    class_count = len(classes)
    bins = [unittest.TestSuite() for i in range(class_count+1)]
    partition_suite(suite, classes, bins)
    for i in range(class_count):
        bins[0].addTests(bins[i+1])
    return bins[0]

Example 8

Project: django-nonrel Source File: simple.py
Function: build_suite
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if '.' in label:
                    suite.addTest(build_test(label))
                else:
                    app = get_app(label)
                    suite.addTest(build_suite(app))
        else:
            for app in get_apps():
                suite.addTest(build_suite(app))

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (TestCase,))

Example 9

Project: hue Source File: simple.py
Function: build_suite
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if '.' in label:
                    suite.addTest(build_test(label))
                else:
                    app = get_app(label)
                    suite.addTest(build_suite(app))
        else:
            for app in get_apps():
                suite.addTest(build_suite(app))

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return runner.reorder_suite(suite, (unittest.TestCase,))

Example 10

Project: django-discover-runner Source File: runner.py
Function: reorder_suite
def reorder_suite(suite, classes):
    """
    Reorders a test suite by test type.

    `classes` is a sequence of types

    All tests of type classes[0] are placed first, then tests of type
    classes[1], etc. Tests with no match in classes are placed last.
    """
    class_count = len(classes)
    bins = [unittest.TestSuite() for i in range(class_count + 1)]
    partition_suite(suite, classes, bins)
    for i in range(class_count):
        bins[0].addTests(bins[i + 1])
    return bins[0]

Example 11

Project: GAE-Bulk-Mailer Source File: simple.py
def build_suite(app_module):
    """
    Create a complete Django test suite for the provided application module.
    """
    suite = unittest.TestSuite()

    # Load unit and doctests in the models.py module. If module has
    # a suite() method, use it. Otherwise build the test suite ourselves.
    if hasattr(app_module, 'suite'):
        suite.addTest(app_module.suite())
    else:
        suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
            app_module))
        try:
            suite.addTest(doctest.DocTestSuite(app_module,
                                               checker=doctestOutputChecker,
                                               runner=DocTestRunner))
        except ValueError:
            # No doc tests in models.py
            pass

    # Check to see if a separate 'tests' module exists parallel to the
    # models module
    test_module = get_tests(app_module)
    if test_module:
        # Load unit and doctests in the tests.py module. If module has
        # a suite() method, use it. Otherwise build the test suite ourselves.
        if hasattr(test_module, 'suite'):
            suite.addTest(test_module.suite())
        else:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
                test_module))
            try:
                suite.addTest(doctest.DocTestSuite(
                    test_module, checker=doctestOutputChecker,
                    runner=DocTestRunner))
            except ValueError:
                # No doc tests in tests.py
                pass
    return suite

Example 12

Project: GAE-Bulk-Mailer Source File: simple.py
def partition_suite(suite, classes, bins):
    """
    Partitions a test suite by test type.

    classes is a sequence of types
    bins is a sequence of TestSuites, one more than classes

    Tests of type classes[i] are added to bins[i],
    tests with no match found in classes are place in bins[-1]
    """
    for test in suite:
        if isinstance(test, unittest.TestSuite):
            partition_suite(test, classes, bins)
        else:
            for i in range(len(classes)):
                if isinstance(test, classes[i]):
                    bins[i].addTest(test)
                    break
            else:
                bins[-1].addTest(test)

Example 13

Project: django-test-tools Source File: test_runner.py
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()
        if test_labels:
            for test_label in test_labels:
                # Handle case when app defined with dot
                if '.' in test_label and test_label not in self.get_apps():
                    app_name = test_label.split('.')[0]
                    for app_label in self.get_apps():
                        if test_label.startswith(app_label):
                            app_name = app_label
                    test_module = get_test_module(app_name)

                    parts = test_label[len(app_name) + 1:].split('.')
                    test_module_name = parts[0]
                    new_suite = build_suite(get_app(app_name.split('.')[-1]))
                    if is_custom_test_package(test_module) and not \
                                                        suite.countTestCases():
                        test_module = import_module('.'.join([
                                        app_name, 'tests', test_module_name]))

                        parts_num = len(parts)
                        if parts_num == 1:
                            new_suite = defaultTestLoader.loadTestsFromModule(
                                                                test_module)
                        if parts_num == 2:
                            new_suite = defaultTestLoader.loadTestsFromName(
                                                        parts[1], test_module)
                        elif parts_num == 3:
                            klass = getattr(test_module, parts[1])
                            new_suite = klass(parts[2])

                    suite.addTest(new_suite)
                else:
                    for test_suite in self.load_from_app(test_label):
                        suite.addTest(test_suite)
        else:
            for app in self.get_apps():
                for test_suite in self.load_from_app(app):
                    suite.addTest(test_suite)

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (TestCase,))

Example 14

Project: PyClassLessons Source File: simple.py
Function: build_suite
def build_suite(app_config):
    """
    Create a complete Django test suite for the provided application module.
    """
    suite = unittest.TestSuite()

    # Load unit and doctests in the models.py module. If module has
    # a suite() method, use it. Otherwise build the test suite ourselves.
    models_module = app_config.models_module
    if models_module:
        if hasattr(models_module, 'suite'):
            suite.addTest(models_module.suite())
        else:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
                models_module))
            try:
                suite.addTest(make_doctest(models_module))
            except ValueError:
                # No doc tests in models.py
                pass

    # Check to see if a separate 'tests' module exists parallel to the
    # models module
    tests_module = get_tests(app_config)
    if tests_module:
        # Load unit and doctests in the tests.py module. If module has
        # a suite() method, use it. Otherwise build the test suite ourselves.
        if hasattr(tests_module, 'suite'):
            suite.addTest(tests_module.suite())
        else:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
                tests_module))
            try:
                suite.addTest(make_doctest(tests_module))
            except ValueError:
                # No doc tests in tests.py
                pass
    return suite

Example 15

Project: splunk-webframework Source File: test_envelope.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(EnvelopeTest))
    return s

Example 16

Project: splunk-webframework Source File: test_geom.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(OGRGeomTest))
    return s

Example 17

Project: splunk-webframework Source File: test_srs.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(SpatialRefTest))
    return s

Example 18

Project: splunk-webframework Source File: tests.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GeoIPTest))
    return s

Example 19

Project: splunk-webframework Source File: test_geos.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GEOSTest))
    return s

Example 20

Project: splunk-webframework Source File: test_geos_mutation.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GEOSMutationTest))
    return s

Example 21

Project: splunk-webframework Source File: test_mutable_list.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(ListMixinTest))
    s.addTest(unittest.makeSuite(ListMixinTestSingle))
    return s

Example 22

Project: splunk-webframework Source File: test_geoforms.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GeometryFieldTest))
    return s

Example 23

Project: splunk-webframework Source File: test_measure.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(DistanceTest))
    s.addTest(unittest.makeSuite(AreaTest))
    return s

Example 24

Project: splunk-webframework Source File: test_spatialrefsys.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(SpatialRefSysTest))
    return s

Example 25

Project: splunk-webframework Source File: __init__.py
Function: geodjango_suite
def geodjango_suite(apps=True):
    """
    Returns a TestSuite consisting only of GeoDjango tests that can be run.
    """
    import sys
    from django.db.models import get_app

    suite = unittest.TestSuite()

    # Adding the GEOS tests.
    from django.contrib.gis.geos import tests as geos_tests
    suite.addTest(geos_tests.suite())

    # Adding GDAL tests, and any test suite that depends on GDAL, to the
    # suite if GDAL is available.
    from django.contrib.gis.gdal import HAS_GDAL
    if HAS_GDAL:
        from django.contrib.gis.gdal import tests as gdal_tests
        suite.addTest(gdal_tests.suite())
    else:
        sys.stderr.write('GDAL not available - no tests requiring GDAL will be run.\n')

    # Add GeoIP tests to the suite, if the library and data is available.
    from django.contrib.gis.geoip import HAS_GEOIP
    if HAS_GEOIP and hasattr(settings, 'GEOIP_PATH'):
        from django.contrib.gis.geoip import tests as geoip_tests
        suite.addTest(geoip_tests.suite())

    # Finally, adding the suites for each of the GeoDjango test apps.
    if apps:
        for app_name in geo_apps(namespace=False):
            suite.addTest(build_suite(get_app(app_name)))

    return suite

Example 26

Project: django-nonrel Source File: __init__.py
Function: suite
def suite():
    "Builds a test suite for the GDAL tests."
    s = TestSuite()
    map(s.addTest, test_suites)
    return s

Example 27

Project: django-nonrel Source File: __init__.py
Function: suite
def suite():
    "Builds a test suite for the GEOS tests."
    s = TestSuite()
    map(s.addTest, test_suites)
    return s

Example 28

Project: django-nonrel Source File: __init__.py
Function: geodjango_suite
def geodjango_suite(apps=True):
    """
    Returns a TestSuite consisting only of GeoDjango tests that can be run.
    """
    import sys
    from django.db.models import get_app

    suite = unittest.TestSuite()

    # Adding the GEOS tests.
    from django.contrib.gis.geos import tests as geos_tests
    suite.addTest(geos_tests.suite())

    # Adding the measurment tests.
    from django.contrib.gis.tests import test_measure
    suite.addTest(test_measure.suite())

    # Adding GDAL tests, and any test suite that depends on GDAL, to the
    # suite if GDAL is available.
    from django.contrib.gis.gdal import HAS_GDAL
    if HAS_GDAL:
        from django.contrib.gis.gdal import tests as gdal_tests
        suite.addTest(gdal_tests.suite())

        from django.contrib.gis.tests import test_spatialrefsys, test_geoforms
        suite.addTest(test_spatialrefsys.suite())
        suite.addTest(test_geoforms.suite())
    else:
        sys.stderr.write('GDAL not available - no tests requiring GDAL will be run.\n')

    # Add GeoIP tests to the suite, if the library and data is available.
    from django.contrib.gis.utils import HAS_GEOIP
    if HAS_GEOIP and hasattr(settings, 'GEOIP_PATH'):
        from django.contrib.gis.tests import test_geoip
        suite.addTest(test_geoip.suite())

    # Finally, adding the suites for each of the GeoDjango test apps.
    if apps:
        for app_name in geo_apps(namespace=False):
            suite.addTest(build_suite(get_app(app_name)))

    return suite

Example 29

Project: django-nonrel Source File: simple.py
def build_suite(app_module):
    "Create a complete Django test suite for the provided application module"
    suite = unittest.TestSuite()

    # Load unit and doctests in the models.py module. If module has
    # a suite() method, use it. Otherwise build the test suite ourselves.
    if hasattr(app_module, 'suite'):
        suite.addTest(app_module.suite())
    else:
        suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(app_module))
        try:
            suite.addTest(doctest.DocTestSuite(app_module,
                                               checker=doctestOutputChecker,
                                               runner=DocTestRunner))
        except ValueError:
            # No doc tests in models.py
            pass

    # Check to see if a separate 'tests' module exists parallel to the
    # models module
    test_module = get_tests(app_module)
    if test_module:
        # Load unit and doctests in the tests.py module. If module has
        # a suite() method, use it. Otherwise build the test suite ourselves.
        if hasattr(test_module, 'suite'):
            suite.addTest(test_module.suite())
        else:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module))
            try:
                suite.addTest(doctest.DocTestSuite(test_module,
                                                   checker=doctestOutputChecker,
                                                   runner=DocTestRunner))
            except ValueError:
                # No doc tests in tests.py
                pass
    return suite

Example 30

Project: hue Source File: runner.py
Function: build_suite
    def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
        suite = TestSuite()
        test_labels = test_labels or ['.']
        extra_tests = extra_tests or []

        discover_kwargs = {}
        if self.pattern is not None:
            discover_kwargs['pattern'] = self.pattern
        if self.top_level is not None:
            discover_kwargs['top_level_dir'] = self.top_level

        for label in test_labels:
            kwargs = discover_kwargs.copy()
            tests = None

            label_as_path = os.path.abspath(label)

            # if a module, or "module.ClassName[.method_name]", just run those
            if not os.path.exists(label_as_path):
                tests = self.test_loader.loadTestsFromName(label)
            elif os.path.isdir(label_as_path) and not self.top_level:
                # Try to be a bit smarter than unittest about finding the
                # default top-level for a given directory path, to avoid
                # breaking relative imports. (Unittest's default is to set
                # top-level equal to the path, which means relative imports
                # will result in "Attempted relative import in non-package.").

                # We'd be happy to skip this and require dotted module paths
                # (which don't cause this problem) instead of file paths (which
                # do), but in the case of a directory in the cwd, which would
                # be equally valid if considered as a top-level module or as a
                # directory path, unittest unfortunately prefers the latter.

                top_level = label_as_path
                while True:
                    init_py = os.path.join(top_level, '__init__.py')
                    if os.path.exists(init_py):
                        try_next = os.path.dirname(top_level)
                        if try_next == top_level:
                            # __init__.py all the way down? give up.
                            break
                        top_level = try_next
                        continue
                    break
                kwargs['top_level_dir'] = top_level


            if not (tests and tests.countTestCases()):
                # if no tests found, it's probably a package; try discovery
                tests = self.test_loader.discover(start_dir=label, **kwargs)

                # make unittest forget the top-level dir it calculated from this
                # run, to support running tests from two different top-levels.
                self.test_loader._top_level_dir = None

            suite.addTests(tests)

        for test in extra_tests:
            suite.addTest(test)

        return reorder_suite(suite, self.reorder_by)

Example 31

Project: hue Source File: simple.py
Function: build_suite
def build_suite(app_module):
    """
    Create a complete Django test suite for the provided application module.
    """
    suite = unittest.TestSuite()

    # Load unit and doctests in the models.py module. If module has
    # a suite() method, use it. Otherwise build the test suite ourselves.
    if hasattr(app_module, 'suite'):
        suite.addTest(app_module.suite())
    else:
        suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
            app_module))
        try:
            suite.addTest(make_doctest(app_module))
        except ValueError:
            # No doc tests in models.py
            pass

    # Check to see if a separate 'tests' module exists parallel to the
    # models module
    test_module = get_tests(app_module)
    if test_module:
        # Load unit and doctests in the tests.py module. If module has
        # a suite() method, use it. Otherwise build the test suite ourselves.
        if hasattr(test_module, 'suite'):
            suite.addTest(test_module.suite())
        else:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(
                test_module))
            try:
                suite.addTest(make_doctest(test_module))
            except ValueError:
                # No doc tests in tests.py
                pass
    return suite

Example 32

Project: hunch-gift-app Source File: tests.py
Function: suite
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(LayerMapTest))
    return s

Example 33

Project: hunch-gift-app Source File: __init__.py
Function: build_suite
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        """
        This method is overridden to construct a suite consisting only of tests
        for GeoDjango.
        """
        suite = unittest.TestSuite()

        # Adding the GEOS tests.
        from django.contrib.gis.geos import tests as geos_tests
        suite.addTest(geos_tests.suite())

        # Adding the measurment tests.
        from django.contrib.gis.tests import test_measure
        suite.addTest(test_measure.suite())

        # Adding GDAL tests, and any test suite that depends on GDAL, to the
        # suite if GDAL is available.
        from django.contrib.gis.gdal import HAS_GDAL
        if HAS_GDAL:
            from django.contrib.gis.gdal import tests as gdal_tests
            suite.addTest(gdal_tests.suite())

            from django.contrib.gis.tests import test_spatialrefsys, test_geoforms
            suite.addTest(test_spatialrefsys.suite())
            suite.addTest(test_geoforms.suite())
        else:
            sys.stderr.write('GDAL not available - no tests requiring GDAL will be run.\n')

        # Add GeoIP tests to the suite, if the library and data is available.
        from django.contrib.gis.utils import HAS_GEOIP
        if HAS_GEOIP and hasattr(settings, 'GEOIP_PATH'):
            from django.contrib.gis.tests import test_geoip
            suite.addTest(test_geoip.suite())

        # Finally, adding the suites for each of the GeoDjango test apps.
        for app_name in self.geo_apps:
            suite.addTest(build_suite(get_app(app_name)))

        return suite

Example 34

Project: django-discover-runner Source File: runner.py
Function: build_suite
    def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
        suite = TestSuite()
        test_labels = test_labels or ['.']
        extra_tests = extra_tests or []

        discover_kwargs = {}
        if self.pattern is not None:
            discover_kwargs['pattern'] = self.pattern
        if self.top_level is not None:
            discover_kwargs['top_level_dir'] = self.top_level

        for label in test_labels:
            kwargs = discover_kwargs.copy()
            tests = None

            label_as_path = os.path.abspath(label)

            # if a module, or "module.ClassName[.method_name]", just run those
            if not os.path.exists(label_as_path):
                tests = self.test_loader.loadTestsFromName(label)
            elif os.path.isdir(label_as_path) and not self.top_level:
                # Try to be a bit smarter than unittest about finding the
                # default top-level for a given directory path, to avoid
                # breaking relative imports. (Unittest's default is to set
                # top-level equal to the path, which means relative imports
                # will result in "Attempted relative import in non-package.").

                # We'd be happy to skip this and require dotted module paths
                # (which don't cause this problem) instead of file paths (which
                # do), but in the case of a directory in the cwd, which would
                # be equally valid if considered as a top-level module or as a
                # directory path, unittest unfortunately prefers the latter.

                top_level = label_as_path
                while True:
                    init_py = os.path.join(top_level, '__init__.py')
                    if os.path.exists(init_py):
                        try_next = os.path.dirname(top_level)
                        if try_next == top_level:
                            # __init__.py all the way down? give up.
                            break
                        top_level = try_next
                        continue
                    break
                kwargs['top_level_dir'] = top_level

            if not (tests and tests.countTestCases()):
                # if no tests found, it's probably a package; try discovery
                tests = self.test_loader.discover(start_dir=label, **kwargs)

                # make unittest forget the top-level dir it calculated from the
                # run, to support running tests from two different top-levels.
                self.test_loader._top_level_dir = None

            suite.addTests(tests)

        for test in extra_tests:
            suite.addTest(test)

        return reorder_suite(suite, self.reorder_by)