Ejemplo n.º 1
0
def main():
    # Configure python path
    parent = os.path.dirname(os.path.abspath(__file__))
    if not parent in sys.path:
        sys.path.insert(0, parent)

    # Configure logging
    logging.basicConfig(level=logging.ERROR)

    # Configure setup
    from cio.conf import settings
    settings.configure(STORAGE={
        'BACKEND': 'sqlite://',
        'NAME': ':memory:',
        'OPTIONS': {
            'check_same_thread': False
        }
    })

    # Run tests
    tests = TestLoader.discover('tests')
    suite = TestSuite(tests)
    result = TestRunner(verbosity=1, failfast=False).run(suite)
    exit_code = len(result.failures) + len(result.errors)

    sys.exit(exit_code)
Ejemplo n.º 2
0
def get_case(test_dir, entry, browser_type, device, version,
             browser_platform, session_name, javascript_disabled,
             webdriver_remote_url, screenshots_on,
             custom_options=None, context=None, failfast=False,
             debug=False, extended=False, saucelabs_enabled=False,
             browserstack_enabled=False, vagrant_enabled=False, skip_tracking=False):
    # our naming convention for tests requires that script-based tests must
    # not begin with "test_*."  SSTTestCase class-based or other
    # unittest.TestCase based source files must begin with "test_*".
    # we also scan the source file to see if it has class definitions,
    # since script base cases normally don't, but TestCase class-based
    # tests always will.

    properties = {
        'script_dir': test_dir,
        'script_name': entry,
        'browser_type': browser_type,
        'device': device,
        'version': version,
        'browser_platform': browser_platform,
        'webdriver_remote_url': webdriver_remote_url,
        'custom_options': custom_options,
        # TODO: session_name should be the test class name, at least for saucelabs
        'session_name': session_name,
        'javascript_disabled': javascript_disabled,
        'screenshots_on': screenshots_on,
        'debug_post_mortem': debug,
        'extended_report': extended,
        'saucelabs_enabled': saucelabs_enabled,
        'browserstack_enabled': browserstack_enabled,
        'vagrant_enabled': vagrant_enabled,
        'skip_tracking': skip_tracking
    }

    if config.saucelabs_enabled:
        from .drivers.sauce.saucelabs_driver import SauceLabsDriver
        properties['webdriver_class'] = SauceLabsDriver
    elif config.browserstack_enabled:
        from .drivers.sauce.browserstack_driver import BrowserStackDriver
        properties['webdriver_class'] = BrowserStackDriver
    elif config.vagrant_enabled:
        from .drivers.sauce.vagrant_driver import VagrantDriver
        properties['webdriver_class'] = VagrantDriver

    if entry.startswith('test_') and _has_classes(test_dir, entry):
        defaultTestLoader.suiteClass = SSTSuite
        # load just the individual file's tests
        this_test = defaultTestLoader.discover(test_dir, pattern=entry)
        this_test.set_test_case_properties(properties)
    else:  # this is for script-based test
        context = {} if context is None else context
        name = entry[:-3]
        test_name = 'test_%s' % name
        this_test = SSTScriptTestCase(test_name, context)
        # Set properties
        for key, value in properties.iteritems():
            setattr(this_test, key, value)

    return this_test
Ejemplo n.º 3
0
def suite(app, modnames=[], return_covermods=False):
    """Generate the test suite.

    First argument is always the instance to use. Use a real one or a temporary.
    The second argument is a list of modules to be tested. If it is empty (which
    it is by default), all sub-modules of the pyClanSphere package are tested.
    If the second argument is True, this function returns two objects: a
    TestSuite instance and a list of the names of the tested modules. Otherwise
    (which is the default) it only returns the former. This is done so that
    this function can be used as setuptools' test_suite.
    """

    # the app object is used for two purposes:
    # 1) plugins are not usable (i.e. not testable) without an initialised app
    # 2) for functions that require an application object as argument, you can
    #    write >>> my_function(app, ...) in the tests
    # The instance directory of this object is located in the tests directory.
    #
    # setup isn't imported at module level because this way coverage
    # can track the whole pyClanSphere imports

    if return_covermods:
        covermods = []
    suite = TestSuite()

    if modnames == []:
        modnames = find_tp_modules()
    test_files = os.listdir(dirname(__file__))
    for modname in modnames:

        # the fromlist must contain something, otherwise the pyClanSphere
        # package is returned, not our module
        try:
            mod = __import__(modname, None, None, [''])
        except ImportError, exc:
            # some plugins can have external dependencies (e.g. creoleparser,
            # pygments) that are not installed on the machine the tests are
            # run on. Therefore, just skip those (with an error message)
            if 'plugins.' in modname:
                if 'versions.' not in modname and 'tests.' not in modname:
                    sys.stderr.write('could not import plugin %s: %s\n' % (modname, exc))
                continue
            else:
                raise
        suites = [DocTestSuite(mod, extraglobs={'app': app})]
        filename = modname[10:] + '.txt'
        if filename in test_files:
            globs = {'app': app}
            globs.update(mod.__dict__)
            suites.append(DocFileSuite(filename, globs=globs))
        for i, subsuite in enumerate(suites):
            # skip modules without any tests
            if subsuite.countTestCases():
                suite.addTest(subsuite)
                if return_covermods and i == 0:
                    covermods.append(mod)
        if 'tests.' in modname:
            suite.addTests(defaultTestLoader.discover(modname))
Ejemplo n.º 4
0
def load_tests():
    """Returns the test modules for the mongows package.

    The expected output of this function is defined by the unittest module's
    load_tests protocol. unittest.main() will runs tests on the modules
    returned by this function.

    """
    return defaultTestLoader.discover(__name__)
Ejemplo n.º 5
0
def main():
    parent = os.path.dirname(os.path.abspath(__file__))
    if not parent in sys.path:
        sys.path.insert(0, parent)

    # Run tests
    tests = defaultTestLoader.discover('tests')
    suit = TestSuite(tests)
    TextTestRunner(verbosity=2, failfast=False).run(suit)
Ejemplo n.º 6
0
def load_tests():
    """Returns the test modules for the mongows package.

    The expected output of this function is defined by the unittest module's
    load_tests protocol. unittest.main() will runs tests on the modules
    returned by this function.

    """
    return defaultTestLoader.discover(__name__)
Ejemplo n.º 7
0
def get_case(test_dir, entry, browser_type, browser_version,
             browser_platform, session_name, javascript_disabled,
             webdriver_remote_url, screenshots_on,
             context=None, failfast=False, debug=False, extended=False):
	# our naming convention for tests requires that script-based tests must
	# not begin with "test_*."  nsUITestCase class-based or other
	# unittest.TestCase based source files must begin with "test_*".
	# we also scan the source file to see if it has class definitions,
	# since script base cases normally don't, but TestCase class-based
	# tests always will.
	if allscrewedup: print "ENTERING get_case"
	if entry.startswith('test_') and _has_classes(test_dir, entry):
		# load just the individual file's tests
		this_test = defaultTestLoader.discover(test_dir, pattern=entry)
		if allscrewedup: print "ENTERING if clause get_case"
	else:  # this is for script-based test
		if allscrewedup: print "ENTERING else get_case"
		context_provided = True
		if context is None:
			context_provided = False
			context = {}
		name = entry[:-3]
		app_type = "web"
		if name.startswith("native_"):
			app_type = "native"
		elif name.startswith("hybrid_"):
			app_type = "hybrid"
		if allscrewedup: print "name - %s" % name
		test_name = 'test_%s' % name
		if allscrewedup: print "test_name - %s" % test_name
		this_test = None
		if app_type == "web":
			this_test = nsUIWebScriptTestCase(test_name, context)
		elif app_type == "native":
			this_test = nsUINativeScriptTestCase(test_name, context)
		this_test.script_dir = test_dir
		this_test.script_name = entry
		this_test.browser_type = browser_type
		this_test.browser_version = browser_version
		this_test.browser_platform = browser_platform
		this_test.webdriver_remote_url = webdriver_remote_url

		this_test.session_name = session_name
		this_test.javascript_disabled = javascript_disabled

		this_test.screenshots_on = screenshots_on
		this_test.debug_post_mortem = debug
		this_test.extended_report = extended

		if allscrewedup: print "ENTERING get_case" + str(this_test)
		return this_test
def get_case(test_dir, entry, browser_type, browser_version,
             browser_platform, session_name, javascript_disabled,
             webdriver_remote_url, screenshots_on,
             context=None, failfast=False, debug=False, extended=False):
    # our naming convention for tests requires that script-based tests must
    # not begin with "test_*."  SSTTestCase class-based or other
    # unittest.TestCase based source files must begin with "test_*".
    # we also scan the source file to see if it has class definitions,
    # since script base cases normally don't, but TestCase class-based
    # tests always will.
    if entry.startswith('test_') and _has_classes(test_dir, entry):
        # load just the individual test
        this_test = defaultTestLoader.discover(test_dir, pattern=entry)
    else:  # this is for script-based test
        context_provided = True
        if context is None:
            context_provided = False
            context = {}
        name = entry[:-3]
        test_name = 'test_%s' % name
        this_test = SSTScriptTestCase(test_name, context)
        this_test.script_dir = test_dir
        this_test.script_name = entry
        this_test.browser_type = browser_type
        this_test.browser_version = browser_version
        this_test.browser_platform = browser_platform
        this_test.webdriver_remote_url = webdriver_remote_url

        this_test.session_name = session_name
        this_test.javascript_disabled = javascript_disabled

        this_test.screenshots_on = screenshots_on
        this_test.debug_post_mortem = debug
        this_test.extended_report = extended

    return this_test