Python testscenarios.generate_scenarios() Examples

The following are 9 code examples of testscenarios.generate_scenarios(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module testscenarios , or try the search function .
Example #1
Source File: test_fixtures.py    From oslo.db with Apache License 2.0 6 votes vote down vote up
def test_module_level(self):
        load_tests = test_fixtures.optimize_module_test_loader()

        loader = unittest.TestLoader()

        found_tests = loader.discover(start_dir, pattern="test_fixtures.py")
        new_loader = load_tests(loader, found_tests, "test_fixtures.py")

        self.assertTrue(
            isinstance(new_loader, testresources.OptimisingTestSuite)
        )

        actual_tests = unittest.TestSuite(
            testscenarios.generate_scenarios(found_tests)
        )

        self.assertEqual(
            new_loader.countTestCases(), actual_tests.countTestCases()
        ) 
Example #2
Source File: test_fixtures.py    From oslo.db with Apache License 2.0 6 votes vote down vote up
def _test_package_level(self, fn):
        load_tests = fn(
            os.path.join(start_dir, "__init__.py"))

        loader = unittest.TestLoader()

        new_loader = load_tests(
            loader, unittest.suite.TestSuite(), "test_fixtures.py")

        self.assertTrue(
            isinstance(new_loader, testresources.OptimisingTestSuite)
        )

        actual_tests = unittest.TestSuite(
            testscenarios.generate_scenarios(
                loader.discover(start_dir, pattern="test_fixtures.py"))
        )

        self.assertEqual(
            new_loader.countTestCases(), actual_tests.countTestCases()
        ) 
Example #3
Source File: noseplug.py    From maas with GNU Affero General Public License v3.0 6 votes vote down vote up
def makeTest(self, obj, parent):
        """Attempt to expand test scenarios in the given test or tests.

        If `obj` is a test case class, this loads tests and expands scenarios.

        If `parent` is a test case class, this assumes that `obj` is a method,
        instantiates the test case, then expands scenarios.

        Everything else is ignored so the loader that invoked this will revert
        to its default behaviour.
        """
        # obj may be a test case class.
        if isinstance(obj, type):
            if issubclass(obj, unittest.TestCase):
                loader = self._getTestLoader()
                tests = loader.loadTestsFromTestCase(obj)
                tests = map(self._unwrapTest, tests)
                return generate_scenarios(tests)
        # obj may be a function/method.
        elif isinstance(parent, type):
            if issubclass(parent, unittest.TestCase):
                test = parent(obj.__name__)
                return generate_scenarios(test) 
Example #4
Source File: __init__.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def load_tests(loader, standard_tests, pattern):
    # top level directory cached on loader instance
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    result = loader.suiteClass()
    result.addTests(testscenarios.generate_scenarios(standard_tests))
    result.addTests(testscenarios.generate_scenarios(package_tests))
    return result 
Example #5
Source File: test_fixtures.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def optimize_package_test_loader(file_):
    """Organize package-level tests into a testresources.OptimizingTestSuite.

    This function provides a unittest-compatible load_tests hook
    for a given package; for per-module, use the
    :func:`.optimize_module_test_loader` function.

    When a unitest or subunit style
    test runner is used, the function will be called in order to
    return a TestSuite containing the tests to run; this function
    ensures that this suite is an OptimisingTestSuite, which will organize
    the production of test resources across groups of tests at once.

    The function is invoked as::

        from oslo_db.sqlalchemy import test_base

        load_tests = test_base.optimize_package_test_loader(__file__)

    The loader *must* be present in the package level __init__.py.

    The function also applies testscenarios expansion to all  test collections.
    This so that an existing test suite that already needs to build
    TestScenarios from a load_tests call can still have this take place when
    replaced with this function.

    """

    this_dir = os.path.dirname(file_)

    def load_tests(loader, found_tests, pattern):
        result = testresources.OptimisingTestSuite()
        result.addTests(found_tests)
        pkg_tests = loader.discover(start_dir=this_dir, pattern=pattern)
        result.addTests(testscenarios.generate_scenarios(pkg_tests))

        return result
    return load_tests 
Example #6
Source File: test_fixtures.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def optimize_module_test_loader():
    """Organize module-level tests into a testresources.OptimizingTestSuite.

    This function provides a unittest-compatible load_tests hook
    for a given module; for per-package, use the
    :func:`.optimize_package_test_loader` function.

    When a unitest or subunit style
    test runner is used, the function will be called in order to
    return a TestSuite containing the tests to run; this function
    ensures that this suite is an OptimisingTestSuite, which will organize
    the production of test resources across groups of tests at once.

    The function is invoked as::

        from oslo_db.sqlalchemy import test_base

        load_tests = test_base.optimize_module_test_loader()

    The loader *must* be present in an individual module, and *not* the
    package level __init__.py.

    The function also applies testscenarios expansion to all  test collections.
    This so that an existing test suite that already needs to build
    TestScenarios from a load_tests call can still have this take place when
    replaced with this function.

    """

    def load_tests(loader, found_tests, pattern):
        result = testresources.OptimisingTestSuite()
        result.addTests(testscenarios.generate_scenarios(found_tests))
        return result
    return load_tests 
Example #7
Source File: __init__.py    From python-libmaas with GNU Affero General Public License v3.0 5 votes vote down vote up
def __call__(self, result=None):
        if self._get_scenarios():
            for test in testscenarios.generate_scenarios(self):
                test.__call__(result)
        else:
            super(WithScenarios, self).__call__(result) 
Example #8
Source File: scenarios.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def __call__(self, result=None):
        if self._get_scenarios():
            for test in testscenarios.generate_scenarios(self):
                test.__call__(result)
        else:
            super().__call__(result) 
Example #9
Source File: __init__.py    From keras-lambda with MIT License 5 votes vote down vote up
def load_tests(loader, standard_tests, pattern):
    # top level directory cached on loader instance
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    result = loader.suiteClass()
    result.addTests(testscenarios.generate_scenarios(standard_tests))
    result.addTests(testscenarios.generate_scenarios(package_tests))
    return result