From 9e685499ffd672551f74815720738722cf6eb669 Mon Sep 17 00:00:00 2001 From: Kevin Kubasik Date: Wed, 17 Jun 2009 01:27:31 +0000 Subject: [PATCH] [gsoc2009-testing] reworking runtests.py so its custom runtime environment doesn't interfear with the test_windmill environment git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11017 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/runtests.py | 81 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/tests/runtests.py b/tests/runtests.py index 330e15f784..982293c7f0 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -165,12 +165,83 @@ def django_tests(verbosity, interactive, test_labels): test_runner = get_runner(settings, coverage=True, reports=True) tr = test_runner() failures = tr.run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests) - if failures: - sys.exit(failures) - from django.core.management.commands.test_windmill import Command as testwm_cmd - windmill_runner = testwm_cmd() - windmill_runner.handle() + from django.core.management.commands.test_windmill import ServerContainer, attempt_import + # as testwm_cmd + # windmill_runner = testwm_cmd() + # windmill_runner.handle() + from windmill.conf import global_settings + from windmill.authoring.djangotest import WindmillDjangoUnitTest + # if 'ie' in labels: + # global_settings.START_IE = True + # sys.argv.remove('ie') + # elif 'safari' in labels: + # global_settings.START_SAFARI = True + # sys.argv.remove('safari') + # elif 'chrome' in labels: + # global_settings.START_CHROME = True + # sys.argv.remove('chrome') + # else: + global_settings.START_FIREFOX = True + # if 'firefox' in labels: + # sys.argv.remove('firefox') + + # if 'manage.py' in sys.argv: + # sys.argv.remove('manage.py') + # if 'test_windmill' in sys.argv: + # sys.argv.remove('test_windmill') + server_container = ServerContainer() + server_container.start_test_server() + + global_settings.TEST_URL = 'http://localhost:%d' % server_container.server_thread.port + + # import windmill + # windmill.stdout, windmill.stdin = sys.stdout, sys.stdin + from windmill.authoring import setup_module, teardown_module + + # from django.conf import settings + tests = [] + for name in settings.INSTALLED_APPS: + for suffix in ['tests', 'wmtests', 'windmilltests']: + x = attempt_import(name, suffix) + if x is not None: tests.append((suffix,x,)); + + wmtests = [] + for (ttype, mod,) in tests: + if ttype == 'tests': + for ucls in [getattr(mod, x) for x in dir(mod) + if ( type(getattr(mod, x, None)) in (types.ClassType, + types.TypeType) ) and + issubclass(getattr(mod, x), WindmillDjangoUnitTest) + ]: + wmtests.append(ucls.test_dir) + + else: + if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'): + wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1])) + else: + wmtests.append(os.path.abspath(mod.__file__)) + + if len(wmtests) is 0: + print 'Sorry, no windmill tests found.' + else: + testtotals = {} + x = logging.getLogger() + x.setLevel(0) + from windmill.server.proxy import logger + from functest import bin + from functest import runner + runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) ) + import windmill + setup_module(tests[0][1]) + sys.argv = sys.argv + wmtests + bin.cli() + teardown_module(tests[0][1]) + # if testtotals['fail'] is not 0: + # sleep(.5) + # sys.exit(1) + if failures or testtotals['fail'] is not 0: + sys.exit(failures + testtotals['fail']) # Restore the old settings. settings.INSTALLED_APPS = old_installed_apps settings.ROOT_URLCONF = old_root_urlconf