コード例 #1
0
def run_tests(test_labels=APPS, verbosity=1, interactive=True, extra_tests=[]):
    """Hack on top of django.test.simple.run_tests to use the XML test runner
    provided by Bitten"""
    setup_test_environment()
    settings.DEBUG = False
    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))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase,))
    old_name = settings.DATABASE_NAME
    from django.db import connection

    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    result = XMLTestRunner(stream=sys.stdout, xml_stream=open("test-results.xml", "w")).run(suite)
    connection.creation.destroy_test_db(old_name, verbosity)

    teardown_test_environment()

    return result
コード例 #2
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if "." in label:
                    from django.test.simple import build_test

                    suite.addTest(build_test(label))
                else:
                    sub_suite = self.find_tests_and_apps(label)
                    suite.addTest(sub_suite)
        else:
            from django.db.models import get_apps

            for app in get_apps():
                from django.test.simple import build_suite

                suite.addTest(build_suite(app))

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

        from django.test.simple import reorder_suite
        from unittest import TestCase

        return reorder_suite(suite, (TestCase,))
コード例 #3
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """Run the unit tests without using the ORM.
    """
    setup_test_environment()

    settings.DEBUG = False
    settings.DATABASE_SUPPORTS_TRANSACTIONS = False
    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))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase,))

    runner = unittest.TextTestRunner(verbosity=verbosity)
    result = runner.run(suite)

    teardown_test_environment()

    return len(result.failures) + len(result.errors)
コード例 #4
0
ファイル: jenkins.py プロジェクト: cyberj/django-ignoretests
    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:
            # Get ignored tests
            ignored_labels = getattr(settings, "IGNORE_TESTS", ())
            ignored_apps = []
            for ilabel in ignored_labels:
                if "." in ilabel:
                    ilabel = ilabel.split(".")[-1]
                app = get_app(ilabel)
                ignored_apps.append(app)

            for app in get_apps():
                if app not in ignored_apps:
                    suite.addTest(build_suite(app))

        suite = reorder_suite(suite, (TestCase,))
        # signals.build_suite.send(sender=self, suite=suite)
        return suite
コード例 #5
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    # Same as django.test.simple.run_tests but return the result object.
    # http://code.djangoproject.com/browser/django/trunk/django/test/simple.py#L149
    setup_test_environment()

    settings.DEBUG = False
    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))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase,))

    old_name = settings.DATABASE_NAME
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    connection.creation.destroy_test_db(old_name, verbosity)

    teardown_test_environment()

    return result
コード例 #6
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                if '.' in label:
                    appname, test = label.split('.', 1)
                else:
                    appname, test = label, ''

                def filter_test(testcase, testprefix=label):
                    testname = "%s.%s.%s" % (testcase.__class__.__module__, testcase.__class__.__name__, testcase)
                    return testname.startswith(testprefix)

                app = get_app(appname)
                suite.addTest(simple.build_suite(app))
                self.filter_suite(suite, filter_test)
        else:
            for appname in settings.OUR_APPS:
                app = get_app(appname, emptyOK=True)
                if app is None:
                    continue
                suite.addTest(simple.build_suite(app))

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

        return simple.reorder_suite(suite, (testcases.TestCase,))
コード例 #7
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None

        # Do default test loading if no test labels specfied
        if not test_labels:
            suite = unittest.TestSuite()
            for app in get_apps():
                suite.addTest(build_suite(app))

            # Then intelligent test find from top directory
            suite.addTest(unittest.defaultTestLoader.discover('.'))

        # If 'projectapps' in test_labels then find only the tests in my
        # project, but find all of them
        if 'projectapps' in test_labels:
            suite = unittest.TestSuite()
            suite.addTest(unittest.defaultTestLoader.discover('.'))

        # Else can only handle a single project name or a series of tests
        elif test_labels:
            root = '.'
            # Loads tests from dotted tests names
            suite = unittest.defaultTestLoader.loadTestsFromNames(test_labels)
            # if single named module has no tests, do discovery within it
            if not suite.countTestCases() and len(test_labels) == 1:
                suite = None
                root = import_module(test_labels[0]).__path__[0]
                suite = unittest.defaultTestLoader.discover(root)

        # Default DjangoTestSuiteRunner behavior
        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (TestCase,))
コード例 #8
0
ファイル: runner.py プロジェクト: javiertejero/django-behave
    def build_suite(self, test_labels, extra_tests=None, **kwargs):

        # build standard Django test suite
        #suite = DjangoTestSuiteRunner.build_suite(self, test_labels, extra_tests, **kwargs)

        #
        # TEMP: for now, ignore any tests but feature tests
        # This will become an option
        #
        suite = unittest.TestSuite()
        
	#
	# Add any BDD tests to it
	#

	# always get all features for given apps (for convenience)
	for label in test_labels:
	    if '.' in label:
	        print "Ignoring label with dot in: " % label
		continue
	    app = get_app(label)
	    
	    # Check to see if a separate 'features' module exists,
	    # parallel to the models module
	    features_dir = get_features(app)
            if features_dir is not None:
                # build a test suite for this directory
                features_test_suite = make_test_suite(features_dir)
                suite.addTest(features_test_suite)

	return reorder_suite(suite, (LiveServerTestCase,))
コード例 #9
0
ファイル: testing.py プロジェクト: gdoermann/django-limbo
    def safe_build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if test_labels:
            for label in test_labels:
                try:
                    if '.' in label:
                        suite.addTest(build_test(label))
                    else:
                        app = get_app(label)
                        suite.addTest(build_suite(app))
                except Exception:
                    log.warning("Could not add test for label: %s" %label)
        else:
            for app in get_apps():
                try:
                    suite.addTest(build_suite(app))
                except Exception:
                    log.warning("Could not add tests for app: %s" %app)

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

        return reorder_suite(suite, (TestCase,))
コード例 #10
0
ファイル: runner.py プロジェクト: ageron/commis
    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():
                app_name = guess_app(app)
                for pattern in getattr(settings, 'TEST_WHITELIST', ('%s.*'%__name__.split('.')[0],)):
                    if fnmatch(app_name, pattern):
                        suite.addTest(build_suite(app))
                        break

            for name in getattr(settings, 'TEST_EXTRA', ()):
                mod = import_module(name + '.' + TEST_MODULE)
                extra_suite = unittest.defaultTestLoader.loadTestsFromModule(mod)
                suite.addTest(extra_suite)


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

        return reorder_suite(suite, (TestCase,))
コード例 #11
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        '''
        Override the base class method to return a suite consisting of all
        TestCase subclasses throughought the whole project.
        '''
        if test_labels:
            suite = TestSuite()
        else:
            suite = DjangoTestSuiteRunner.build_suite(
                self, test_labels, extra_tests, **kwargs
            )
        added_test_classes = set(t.__class__ for t in suite)

        loader = TestLoader()
        for fname in _get_module_names(os.getcwd()):
            module = _import(_to_importable_name(fname))
            for test_class in _get_testcases(module):

                if test_class in added_test_classes:
                    continue

                for method_name in loader.getTestCaseNames(test_class):
                    testname = '.'.join([
                        module.__name__, test_class.__name__, method_name
                    ])
                    if self._test_matches(testname, test_labels):
                        suite.addTest(loader.loadTestsFromName(testname))
                        added_test_classes.add(test_class)

        return reorder_suite(suite, (TestCase,))
コード例 #12
0
ファイル: runner.py プロジェクト: uzarubin/django-behave
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        cache = AppCache()

        get_app = cache.get_app
        get_apps = cache.get_apps

        suite = unittest.TestSuite()

        #get all features for given apps
        if test_labels:
            for label in test_labels:
                if '.' in label:
                    print 'Ignoring label with dot in: ' % label
                    continue
                app = get_app(label)

                features_dir = get_features(app)
                if features_dir is not None:
                    suite.addTest(self.make_bdd_test_suite(features_dir))
        else:
            for app in get_apps():
                features_dir = get_features(app)
                if features_dir is not None:
                    suite.addTest(self.make_bdd_test_suite(features_dir))

        return reorder_suite(suite, (LiveServerTestCase,))
コード例 #13
0
ファイル: nose2django.py プロジェクト: Rustem/nose2django
    def startTestRun(self, event):
        """Nose2 hook for the beginning of test running.
        Init the django environ and re-order the tests according to
        the django documented test runner behaviour.
        """
        from django.test.simple import reorder_suite, DjangoTestSuiteRunner
        from django.test.utils import setup_test_environment
        # Init the django default runner so we can call it's functions as needed
        self.dtsr = DjangoTestSuiteRunner()

        setup_test_environment()

        event.suite = reorder_suite(event.suite, (unittest.TestCase,))

        self.old_config = self.dtsr.setup_databases()
        
        if self.session.verbosity > 1:
            # ensure that deprecation warnings are displayed during testing
            # the following state is assumed:
            # logging.capturewarnings is true
            # a "default" level warnings filter has been added for
            # DeprecationWarning. See django.conf.LazySettings._configure_logging
            self.logger = logging.getLogger('py.warnings')
            handler = logging.StreamHandler()
            self.logger.addHandler(handler)
コード例 #14
0
ファイル: __init__.py プロジェクト: cyberj/django-ignoretests
    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:
            # Get ignored tests
            ignored_labels = getattr(settings, "IGNORE_TESTS", ())
            ignored_apps = []
            for ilabel in ignored_labels:
                if "." in ilabel:
                    ilabel = ilabel.split(".")[-1]
                try:
                    app = get_app(ilabel)
                except Exception as e:
                    print e
                else:
                    ignored_apps.append(app)

            for app in get_apps():
                if app not in ignored_apps:
                    suite.addTest(build_suite(app))

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

        return reorder_suite(suite, (TestCase,))
コード例 #15
0
 def get_tests(self):
     if not hasattr(self, "_tests"):
         self._suite = unittest.TestSuite()
         self._suite.addTest(build_suite(self.module))
         self._suite = reorder_suite(self._suite, (TestCase,))
         self._tests = [Test(test, self.label) for test in self._suite._tests]
     return self._tests
コード例 #16
0
ファイル: runner.py プロジェクト: jaydev/django-behave
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        # build standard Django test suite
        suite = unittest.TestSuite()

        #
        # Run Normal Django Test Suite
        #
        std_test_suite = make_test_suite(test_labels, **kwargs)
        suite.addTest(std_test_suite)

        #
        # Add BDD tests to it
        #

        # always get all features for given apps (for convenience)
        for label in test_labels:
            if '.' in label:
                print "Ignoring label with dot in: " % label
                continue
            app = get_app(label)

            # Check to see if a separate 'features' module exists,
            # parallel to the models module
            features_dir = get_features(app)
            if features_dir is not None:
                # build a test suite for this directory
                suite.addTest(make_bdd_test_suite(features_dir))

        return reorder_suite(suite, (LiveServerTestCase,))
コード例 #17
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()

        if not self.selenium_only:
            suite = super(SeleniumTestRunner, self).build_suite(test_labels, extra_tests, **kwargs)

        if self.selenium:
            # Hack to exclude doctests from selenium-only, they are already present
            from django.db.models import get_app
            if test_labels:
                for label in test_labels:
                    if not '.' in label:
                        app = get_app(label)
                        setattr(app, 'suite', unittest.TestSuite)

            # Add tests from seltests.py modules
            import django.test.simple
            orig_test_module = django.test.simple.TEST_MODULE
            django.test.simple.TEST_MODULE = SELTEST_MODULE
            try:
                sel_suite = super(SeleniumTestRunner, self).build_suite(test_labels, extra_tests, **kwargs)
                suite.addTest(sel_suite)
            finally:
                 django.test.simple.TEST_MODULE = orig_test_module

        return reorder_suite(suite, (TestCase,))
コード例 #18
0
ファイル: runner.py プロジェクト: chriscabral/django-jenkins
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        if not test_labels and not self.test_all:
            if hasattr(settings, 'PROJECT_APPS'):
                test_labels = settings.PROJECT_APPS

        suite = super(CITestSuiteRunner, self).build_suite(test_labels, extra_tests=None, **kwargs)
        signals.build_suite.send(sender=self, suite=suite)
        return reorder_suite(suite, getattr(self, 'reorder_by', (TestCase,)))
コード例 #19
0
    def build_suite(self, test_labels, *args, **kwargs):
        """
        Override the default test suite builder to exclude doctests, use
        'tests.selenium' as the test module path, allow excluding the tests of
        any apps contained in settings.SELENIUM['EXCLUDE_APPS'].

        """
        from django.test.simple import (unittest, build_test, get_app,
                get_apps, reorder_suite, TestCase, doctest,
                build_suite as _build_suite)

        # Hack to remove doctests from test suite without reimplementing
        # build_suite
        def _filter_suite(suite):
            tests = []
            for test in suite._tests:
                if isinstance(test, unittest.TestSuite):
                    tests.append(_filter_suite(test))
                elif not isinstance(test, doctest.DocTestCase):
                    tests.append(test)

            suite._tests = tests
            return suite

        def build_suite(*args, **kwargs):
            suite = _build_suite(*args, **kwargs)
            return _filter_suite(suite)

        exclude_apps = settings.SELENIUM_SETUP.get('EXCLUDE_APPS', [])
        test_labels = [l for l in test_labels
                       if all(not l.startswith(app) for app in exclude_apps)]

        import django.test.simple
        orig_test_module = django.test.simple.TEST_MODULE
        django.test.simple.TEST_MODULE = SELENIUM_TEST_MODULE

        try:
            # copied from django TestSuiteRunner
            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():
                    name = app.__name__
                    if all(('.%s' % a) not in name for a in exclude_apps):
                        suite.addTest(build_suite(app))

            return reorder_suite(suite, (TestCase,))

        finally:
            django.test.simple.TEST_MODULE = orig_test_module
コード例 #20
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = TestSuite()
        loader = TestLoader()
        for fname in _get_module_names('.'):
            module = _import(_to_importable_name(fname))
            for test_case in _get_module_testcases(module):
                suite.addTests(loader.loadTestsFromTestCase(test_case))

        return reorder_suite(suite, (TestCase,))
コード例 #21
0
def run(request):
	"""
	Runs all the tests.
	"""

	# Some stuff.
	verbosity=1
	interactive=True
	extra_tests=[]

	# Setup the response.
	response = HttpResponse()

	# Get the installed apps for this project.
	installed_apps = settings.INSTALLED_APPS

	# The list of applications which will be tested.
	test_labels = []

	# Populate the test_labels list with the POST data.
	for item in request.POST.getlist('apps'):
		test_labels.append(settings.INSTALLED_APPS[int(item)])

	try:
		setup_test_environment()

		settings.DEBUG = False
		settings.DATABASE_ENGINE = 'sqlite3'
		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))

		for test in extra_tests:
			suite.addTest(test)

		suite = reorder_suite(suite, (TestCase,))

		old_name = settings.DATABASE_NAME
		from django.db import connection
		connection.creation.create_test_db(verbosity, autoclobber=not interactive)
		result = HTMLTestRunner.HTMLTestRunner(stream=response, verbosity=verbosity).run(suite)
		connection.creation.destroy_test_db(old_name, verbosity)

		teardown_test_environment()
	except Exception, e:
		from ipdb import set_trace; set_trace()
		raise e
コード例 #22
0
ファイル: __init__.py プロジェクト: mrts2/django
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], suite=None):
    """
    Set `TEST_RUNNER` in your settings with this routine in order to
    scaffold test spatial databases correctly for your GeoDjango models.
    For more documentation, please consult the following URL:
      http://geodjango.org/docs/testing.html.
    """
    from django.conf import settings
    from django.db import connection
    from django.db.models import get_app, get_apps
    from django.test.simple import build_suite, build_test
    from django.test.utils import setup_test_environment, teardown_test_environment

    # The `create_test_spatial_db` routine abstracts away all the steps needed
    # to properly construct a spatial database for the backend.
    from django.contrib.gis.db.backend import create_test_spatial_db

    # Setting up for testing.
    setup_test_environment()
    settings.DEBUG = False
    old_name = settings.DATABASE_NAME

    # Creating the test spatial database.
    create_test_spatial_db(verbosity=verbosity, autoclobber=not interactive)

    # The suite may be passed in manually, e.g., when we run the GeoDjango test,
    # we want to build it and pass it in due to some customizations.  Otherwise,
    # the normal test suite creation process from `django.test.simple.run_tests`
    # is used to create the test suite.
    if suite is None:
        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))

        for test in extra_tests:
            suite.addTest(test)

    suite = reorder_suite(suite, (TestCase,))

    # Executing the tests (including the model tests), and destorying the
    # test database after the tests have completed.
    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    connection.creation.destroy_test_db(old_name, verbosity)
    teardown_test_environment()

    # Returning the total failures and errors
    return len(result.failures) + len(result.errors)
コード例 #23
0
    def run_tests(self, test_labels, verbosity=1, interactive=True, extra_tests=[]):
        """
        Run the unit tests for all the test labels in the provided list.
        Labels must be of the form:
         - app.TestClass.test_method
            Run a single specific test method
         - app.TestClass
            Run all the test methods in a given class
         - app
            Search for doctests and unittests in the named application.

        When looking for tests, the test runner will look in the models and
        tests modules for the application.
        
        A list of 'extra' tests may also be provided; these tests
        will be added to the test suite.
        
        Returns the number of tests that failed.
        """
        setup_test_environment()
        
        settings.DEBUG = False
        
        verbose = getattr(settings, 'TEST_OUTPUT_VERBOSE', False)
        descriptions = getattr(settings, 'TEST_OUTPUT_DESCRIPTIONS', False)
        output = getattr(settings, 'TEST_OUTPUT_DIR', '.')
        
        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))
        
        for test in extra_tests:
            suite.addTest(test)

        suite = reorder_suite(suite, (TestCase,))

        old_config = self.setup_databases()

        result = xmlrunner.XMLTestRunner(
            verbose=verbose, descriptions=descriptions, output=output).run(suite)
        
        self.teardown_databases(old_config)
        teardown_test_environment()
        
        return len(result.failures) + len(result.errors)
コード例 #24
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        for label in test_labels:

            if '.' in label:
                parts = label.split('.')
                app = get_project_app(parts[0])
                discovery_root = dirname(app.__file__)
                suite = get_tests(app, parts, discovery_root)
            else:
                app = get_project_app(label)
                app_dir = dirname(app.__file__)
                suite = defaultTestLoader.discover(app_dir, pattern="*test*.py")

        return reorder_suite(suite, (TestCase,))
コード例 #25
0
ファイル: seltest.py プロジェクト: dimagi/luna
    def build_suite(self, test_labels, *args, **kwargs):
        """
        Override the default test suite builder to exclude doctests, use
        'tests.selenium' as the test module path.

        """
        from django.test.simple import (unittest, build_test, get_app,
                get_apps, reorder_suite, TestCase, doctest,
                build_suite as _build_suite)

        # Hack to remove doctests from test suite without reimplementing
        # build_suite
        def _filter_suite(suite):
            tests = []
            for test in suite._tests:
                if isinstance(test, unittest.TestSuite):
                    tests.append(_filter_suite(test))
                elif not isinstance(test, doctest.DocTestCase):
                    tests.append(test)

            suite._tests = tests
            return suite

        def build_suite(*args, **kwargs):
            suite = _build_suite(*args, **kwargs)
            return _filter_suite(suite)

        import django.test.simple
        orig_test_module = django.test.simple.TEST_MODULE
        django.test.simple.TEST_MODULE = SELENIUM_TEST_MODULE

        try:
            # copied from django TestSuiteRunner
            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))

            return reorder_suite(suite, (TestCase,))

        finally:
            django.test.simple.TEST_MODULE = orig_test_module
コード例 #26
0
ファイル: test_runner.py プロジェクト: MattyO/clebikes
	def build_suite(self, test_labels, extra_tests=None, **kwargs):
		suite=None

		if test_labels:
			suite = defaultTestLoader.loadTestsFromNames(test_labels)
		else:
			
			test_labels = [app for app in settings.INSTALLED_APPS if not app.startswith(settings.TEST_IGNORE_APPS) ]
			suite = super(AppTestSuiteRunner,self).build_suite(test_labels)
			suite.addTests(defaultTestLoader.discover('libs'))
			#for test in  defaultTestLoader.discover('libs'):
			#	suite.addTest(test)

		return reorder_suite(suite, (TestCase,))
コード例 #27
0
ファイル: runner.py プロジェクト: cicerocomp/fisl13
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        loader = TestLoader()
        suite = None

        if test_labels:
            suite = loader.loadTestsFromNames(test_labels)

        if suite is None:
            suite = loader.discover(start_dir=settings.BASE_PATH)

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

        return reorder_suite(suite, (TestCase,))
コード例 #28
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()
        
        for label in test_labels or ['person']:
            if '.' in label:
                print "Ignoring label with dot in: " % label
                continue
            app = get_app(label)

            features_dir = get_features(app)
            if features_dir is not None:
                features_test_suite = make_test_suite(features_dir)
                suite.addTest(features_test_suite)

        return reorder_suite(suite, (LiveServerTestCase,))
コード例 #29
0
ファイル: runner.py プロジェクト: rpedigoni/bookshelf
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None

        if test_labels:
            suite = defaultTestLoader.loadTestsFromNames(test_labels)

        if suite is None:
            path = os.path.abspath(os.path.join(settings.BASE_PATH, ".."))
            suite = defaultTestLoader.discover(start_dir=path)

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

        return reorder_suite(suite, (TestCase,))
コード例 #30
0
ファイル: runner.py プロジェクト: pombredanne/abyss
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        loader = TestLoader()
        suite = None

        if test_labels:
            suite = loader.loadTestsFromNames(test_labels)

        if suite is None:
            path = os.path.abspath(os.path.join(settings.BASE_PATH, ".."))
            suite = loader.discover(start_dir=path)

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

        return reorder_suite(suite, (TestCase, ))
コード例 #31
0
    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,))
コード例 #32
0
ファイル: runner.py プロジェクト: zhangqin/w3af-webui
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None
        discovery_root = settings.TEST_DISCOVERY_ROOT
        if test_labels:
            suite = defaultTestLoader.loadTestsFromNames(test_labels)
            if not suite.countTestCases() and len(test_labels) == 1:
                suite = None
                discovery_root = import_module(test_labels[0]).__path__[0]

        if suite is None:
            suite = defaultTestLoader.discover(
                discovery_root,
                top_level_dir=settings._PATH,
            )
        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)
        return reorder_suite(suite, (TestCase, ))
コード例 #33
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None
        discovery_root = settings.TEST_DISCOVERY_ROOT

        if test_labels:
            suite = defaultTestLoader.loadTestsFromNames(test_labels)

        if suite is None:
            suite = defaultTestLoader.discover(
                discovery_root,
                top_level_dir=settings.BASE_PATH,
            )

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

        return reorder_suite(suite, (TestCase, ))
コード例 #34
0
    def build_suite(self, test_labels, *args, **kwargs):
        suite = unittest.TestSuite()

        if not self.selenium_only:
            suite = super(SeleniumTestRunner,
                          self).build_suite(test_labels, *args, **kwargs)

        if self.selenium:
            # Hack to exclude doctests from selenium-only, they are already present
            from django.db.models import get_app
            if test_labels:
                for label in test_labels:
                    if not '.' in label:
                        app = get_app(label)
                        setattr(app, 'suite', unittest.TestSuite)

            sel_suite = self._get_seltests(test_labels, *args, **kwargs)
            suite.addTest(sel_suite)

        return reorder_suite(suite, (TestCase, ))
コード例 #35
0
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():
            app_name = app.__name__
            if app_name.endswith('.models'):
                app_name = app_name[:-7]
            if app_name not in getattr(settings, 'TEST_SKIP_APP_TESTS', ()):
                suite.addTest(build_suite(app))
    if extra_tests:
        for test in extra_tests:
            suite.addTest(test)

    return reorder_suite(suite, (TestCase, ))
コード例 #36
0
    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():
                if app.__name__.startswith('django.'):
                    continue  # disable django built-in tests
                suite.addTest(build_suite(app))

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

        return reorder_suite(suite, (TestCase, ))
コード例 #37
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None
        pattern = '*_test.py'

        # Do default test loading if no test labels specfied
        if not test_labels:
            suite = unittest.TestSuite()
            for app in get_apps():
                suite.addTest(build_suite(app))

            # Then intelligent test find from top directory
            suite.addTest(
                unittest.defaultTestLoader.discover('.', pattern=pattern))

        # If 'projectapps' in test_labels then find only the tests in my
        # project, but find all of them
        if 'projectapps' in test_labels:
            suite = unittest.TestSuite()
            suite.addTest(
                unittest.defaultTestLoader.discover('.', pattern=pattern))

        # Else can only handle a single project name or a series of tests
        elif test_labels:
            root = '.'
            # Loads tests from dotted tests names
            suite = unittest.defaultTestLoader.loadTestsFromNames(test_labels)
            # if single named module has no tests, do discovery within it
            if not suite.countTestCases() and len(test_labels) == 1:
                suite = None
                root = import_module(test_labels[0]).__path__[0]
                suite = unittest.defaultTestLoader.discover(root,
                                                            pattern=pattern)

        # Default DjangoTestSuiteRunner behavior
        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (TestCase, ))
コード例 #38
0
        def build_suite(self, test_labels, extra_tests=None, **kwargs):
            suite = None
            discovery_root = settings.TEST_DISCOVERY_ROOT

            if test_labels:
                suite = defaultTestLoader.loadTestsFromNames(test_labels)
                # if single named module has no tests, do discovery within it
                if not suite.countTestCases() and len(test_labels) == 1:
                    suite = None
                    discovery_root = import_module(test_labels[0]).__path__[0]

            if suite is None:
                suite = defaultTestLoader.discover(
                    discovery_root,
                    top_level_dir=settings.BASE_PATH,
                )

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

            from django.test.simple import reorder_suite  # Django 1.5 and lower
            return reorder_suite(suite, (TestCase,))
コード例 #39
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = None
        discovery_root = settings.TEST_DISCOVERY_ROOT

        testLoader = CustomTestLoader()

        if test_labels:
            suite = testLoader.loadTestsFromNames(test_labels)
            # if single named module has no tests, do discovery within it
            if not suite.countTestCases() and len(test_labels) == 1:
                suite = None
                discovery_root = import_module(test_labels[0]).__path__[0]

        if suite is None:
            suite = testLoader.discover(
                discovery_root,
                top_level_dir=settings.TEST_DISCOVERY_ROOT,
            )

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

        return reorder_suite(suite, (TestCase, ))
コード例 #40
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """
    worsk exactly as per normal test
    but only creates the test_db if it doesn't yet exist
    and does not destroy it when done
    tables are flushed and fixtures loaded between tests as per usual
    but if your schema has not changed then this saves significant amounts of time
    and speeds up the test cycle

    Run the unit tests for all the test labels in the provided list.
    Labels must be of the form:
     - app.TestClass.test_method
        Run a single specific test method
     - app.TestClass
        Run all the test methods in a given class
     - app
        Search for doctests and unittests in the named application.

    When looking for tests, the test runner will look in the models and
    tests modules for the application.

    A list of 'extra' tests may also be provided; these tests
    will be added to the test suite.

    Returns the number of tests that failed.
    """
    setup_test_environment()

    settings.DEBUG = False
    suite = unittest.TestSuite()

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

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase, ))

    old_name = settings.DATABASES['default']['NAME']

    # Everything up to here is from django.test.simple

    from django.db.backends import creation
    from django.db import connection, DatabaseError

    if settings.DATABASES['default']['TEST_NAME']:
        settings.DATABASES['default']['NAME'] = settings.DATABASES['default'][
            'TEST_NAME']
    else:
        settings.DATABASES['default'][
            'NAME'] = creation.TEST_DATABASE_PREFIX + settings.DATABASES[
                'default']['NAME']
    connection.settings_dict["DATABASE_NAME"] = settings.DATABASES['default'][
        'NAME']

    # does test db exist already ?
    try:
        if settings.DATABASES['default']['ENGINE'] == 'sqlite3':
            if not os.path.exists(settings.DATABASES['default']['NAME']):
                raise DatabaseError
        cursor = connection.cursor()
    except Exception:
        # db does not exist
        # juggling !  create_test_db switches the DATABASE_NAME to the TEST_DATABASE_NAME
        settings.DATABASES['default']['NAME'] = old_name
        connection.settings_dict["DATABASE_NAME"] = old_name
        connection.creation.create_test_db(verbosity, autoclobber=True)
    else:
        connection.close()

    settings.DATABASES['default'][
        'SUPPORTS_TRANSACTIONS'] = connections_support_transactions()

    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)

    # Since we don't call destory_test_db, we need to set the db name back.
    settings.DATABASES['default']['NAME'] = old_name
    connection.settings_dict["DATABASE_NAME"] = old_name
    teardown_test_environment()

    return len(result.failures) + len(result.errors)
コード例 #41
0
    def build_suite(self, test_labels, extra_tests, **kwargs):
        """Run tests normally, but also run BDD tests.
        :test_labels: a tuple of test labels specified from the command line, i.e. distributed
        """
        extra_tests = extra_tests or []

        # Output Firefox version, needed to understand Selenium compatibility
        # issues
        browser = webdriver.Firefox()
        print("Successfully setup Firefox {0}".format(
            browser.capabilities['version']))
        browser.quit()
        # Add BDD tests to the extra_tests
        # always get all features for given apps (for convenience)
        bdd_labels = test_labels
        # if e.g. we want to run ALL the tests and so didn't specify any labels
        if not bdd_labels:
            bdd_labels = reduce(lambda l, x: l + [x] if 'kalite' in x else l,
                                settings.INSTALLED_APPS, [])
            # Get rid of the leading "kalite." characters
            bdd_labels = map(lambda s: s[7:], bdd_labels)
            bdd_labels = tuple(bdd_labels)

        # if we don't want any bdd tests, empty out the bdd label list no matter what
        bdd_labels = [] if self._no_bdd else bdd_labels

        ignore_empty_test_labels = False

        for label in bdd_labels:
            feature_name = None
            if '.' in label:
                print(
                    "Found label with dot in: %s, processing individual feature"
                    % label)
                full_label = label
                feature_name = label.split(".")[-1]
                label = label.split(".")[0]
            try:
                app = get_app(label)
            except ImproperlyConfigured as e:
                # Thrown when the app doesn't have any models
                # TODO(MCGallaspy): decide if that's reasonable behavior.
                # It means you can't put behave tests in apps with no models.
                logging.warn(e)
                continue

            # Check to see if a separate 'features' module exists,
            # parallel to the models module
            features_dir = get_features(app)
            if features_dir is not None:
                if feature_name:
                    if check_feature_file(features_dir, feature_name):
                        test_labels = filter(lambda x: x != full_label,
                                             test_labels)
                        # Flag that we should ignore test_labels if empty
                        ignore_empty_test_labels = True
                    else:
                        print("Invalid behave feature name, ignoring")
                        continue
                # build a test suite for this directory
                extra_tests.append(
                    self.make_bdd_test_suite(features_dir,
                                             feature_name=feature_name))

        if not test_labels and ignore_empty_test_labels:
            suite = suite = unittest.TestSuite()

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

            suite = reorder_suite(suite, (unittest.TestCase, ))
        else:
            suite = super(KALiteTestRunner,
                          self).build_suite(test_labels, extra_tests, **kwargs)

        # remove all django module tests
        suite._tests = filter(lambda x: 'django.' not in x.__module__,
                              suite._tests)

        if self._bdd_only:
            suite._tests = filter(
                lambda x: type(x).__name__ == "DjangoBehaveTestCase",
                suite._tests)
        return suite
コード例 #42
0
ファイル: runner.py プロジェクト: key/django-jenkins
 def build_suite(self, test_labels, **kwargs):
     suite = unittest.TestSuite()
     signals.build_suite.send(sender=self, suite=suite)
     return reorder_suite(suite, (TestCase, ))
コード例 #43
0
 def build_suite(self, test_labels, extra_tests=None, **kwargs):
     suite = TestSuite()
     signals.build_suite.send(sender=self, suite=suite)
     return reorder_suite(suite, (TestCase, ))
コード例 #44
0
ファイル: runner.py プロジェクト: chamindu/django-jenkins
 def build_suite(self, test_labels, extra_tests=None, **kwargs):
     suite = super(CITestSuiteRunner, self).build_suite(test_labels,
                                                        extra_tests=None,
                                                        **kwargs)
     signals.build_suite.send(sender=self, suite=suite)
     return reorder_suite(suite, getattr(self, 'reorder_by', (TestCase, )))