Example #1
0
    def handle(self, *labels, **options):

        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://127.0.0.1:%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.dep import functest
            bin = functest.bin
            runner = functest.runner
            runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
            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)
Example #2
0
 def handle(self, *labels, **options):
             
     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)
Example #3
0
    def handle(self, *labels, **options):

        from windmill.conf import global_settings
        from windmill.authoring.djangotest import WindmillDjangoUnitTest

        # Find a browser name in the command line arguments.
        # One it's found, remove the browser from the arguments list.
        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:
            # If no browser is specified, default to firefox.
            global_settings.START_FIREFOX = True
            if 'firefox' in labels:
                sys.argv.remove('firefox')

        # Now remove from the arguments list the command call.
        if 'manage.py' in sys.argv:
            sys.argv.remove('manage.py')
        if 'test_windmill' in sys.argv:
            sys.argv.remove('test_windmill')
        # At this point, sys.argv only contains the name of the tests to run
        # (if any).

        # Start a Django server. It will automatically find a port it is
        # allowed to listen on.
        server_container = ServerContainer()
        server_container.start_test_server()

        # We access this port using .server_thread.port
        global_settings.TEST_URL = 'http://127.0.0.1:%d' % server_container.server_thread.port

        from windmill.authoring import setup_module, teardown_module
        from django.conf import settings

        # Let's try to automatically discover tests in installed Django
        # applications.
        # For example, if you have
        #   INSTALLED_APPS =  ('foo', 'bar')
        # Windmill will try to load:
        #   foo.tests
        #   foo.wmtests
        #   foo.windmilltests
        #   bar.tests
        #   bar.wmtests
        #   bar.windmilltests
        #
        tests = []
        for name in settings.INSTALLED_APPS:
            # TODO put this suffix list in the configuration file.
            for suffix in ['tests', 'wmtests', 'windmilltests']:
                x = attempt_import(name, suffix)
                if x is not None: tests.append((suffix,x,));

        # Now `tests` contains the list of modules which **could** contain some
        # Windmill tests.

        wmtests = []
        
        # In `tests`, modules are stored in the form (module_name, module).
        # As we import *.a_suffix, module_name can only be one of the suffixes.
        for (ttype, mod) in tests:
            if ttype == 'tests':
                # For each attribute of the module which is a Class and is
                # subclass of WindmillDjangoUnitTest
                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)]:
                    # Add it tot the test list
                    wmtests.append(ucls.test_dir)

            else:
                # If the file is __init.py(c)
                if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'):
                    # We add the whole submodule to the tests
                    wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1]))
                else:
                    # Otherwise we just add the module itself
                    wmtests.append(os.path.abspath(mod.__file__))

        # We check if we finally found some usable tests
        if len(wmtests) is 0: # Seriously, testing with `is`, seriously?
            print 'Sorry, no windmill tests found.'
        else:

            # (Note: this is probably the hairiest and the most
            # incomprehensible piece of code I ever read. Perl scripts don't
            # count)

            # If we have something to test
            testtotals = {}

            # Prepare the logger
            x = logging.getLogger()
            x.setLevel(0)

            from windmill.dep import functest
            bin = functest.bin

            # We grab the CLIRunner class. This class wraps each tests and how
            # they are displayed on the console screen.
            runner = functest.runner
            # We override the `final` classmethod (which seems to be called
            # when the test suite is over). We want it to update the totals
            # (FIXME I think they should be called `status` because it's
            # a record of how many tests passed/failed/skipepd).
            runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
            # FIXME OK so why only the very first module found should be
            # loaded?
            setup_module(tests[0][1])

            # Update the command line arguments (SRSLY guys, have you ever
            # heard of functions arguments?)
            sys.argv = sys.argv + wmtests

            # Run the command line function (the one which does the full job).
            bin.cli()

            # Teardown the tested module (let's call it "The One").
            teardown_module(tests[0][1])

            # OK. If we failed, quit the program.
            if testtotals['fail'] is not 0:
                sleep(.5)
                sys.exit(1)