def test_float(self):
     key = "kmet"
     value = 94.7
     name = self.add_module(values={key: value})
     actual = config_for_module(name)[key]
     expect(actual).to(be_a(float))
     expect(actual).to(equal(value))
 def test_str(self):
     key = "ozzie"
     value = "oi"
     name = self.add_module(values={key: value})
     actual = config_for_module(name)[key]
     expect(actual).to(be_a(str))
     expect(actual).to(equal(value))
 def test_bool_true(self):
     key = "tea"
     value = True
     name = self.add_module(values={key: value})
     actual = config_for_module(name)[key]
     expect(actual).to(be_a(bool))
     expect(actual).to(equal(value))
 def test_int(self):
     key = "darcy"
     value = 327
     name = self.add_module(values={key: value})
     actual = config_for_module(name)[key]
     expect(actual).to(be_a(int))
     expect(actual).to(equal(value))
Example #5
0
def run_all(path):
    """
    Run all tests beneath the given path
    """
    cfg = config_for_module(__name__)
    throttle = cfg.delay_between_checks_for_parallel_suite_completion
    limit = cfg.max_parallel_suites
    timeout = _float_or_none(name="$RUN_ALL_TIMEOUT",
                             value=cfg.run_all_timeout)
    if timeout is None:
        expiry = None
    else:
        expiry = dependency(datetime).now() + timedelta(seconds=_float_or_none(
            name="$RUN_ALL_TIMEOUT", value=cfg.run_all_timeout))
    pool = Pool(limit)
    queue = list(discover(path))
    while queue:
        if expiry and dependency(datetime).now() > expiry:
            break
        while pool.has_capacity() and queue:
            pool.add(queue.pop(0))
        log.debug("Waiting in queue: %d" % len(queue))
        sleep(throttle)
    pool.wait_for_jobs(expiry=expiry)
    return pool.failure_count
Example #6
0
def ci_workspace_path():
    vars = dependency(os).environ
    config = config_for_module(__name__)
    key = config.ci_workspace_env_var
    if key in vars.keys():
        return vars[key]
    return None
def launch_chrome():
    config = config_for_module(__name__)
    opts = dependency(webdriver.chrome.options.Options)()
    opts.add_argument("start-fullscreen")
    agent_string = config.chrome_user_agent
    if agent_string:
        opts.add_argument("user-agent=%s" % agent_string)
    return dependency(webdriver).Chrome(chrome_options=opts)
Example #8
0
 def __init__(self):
     self._log = dependency(logger_for_module)(__name__)
     config = config_for_module(__name__)
     self.element_find_timeout = config.browser_element_find_timeout
     self.page_load_timeout = config.browser_page_load_timeout
     self._driver = dependency(launch_browser)()
     self._failure_detected = False
     subscribe_event_handlers(self)
def launch_browser():
    config = config_for_module(__name__)
    launch = get_launch_function()
    return call_with_exception_tolerance(
        func=launch,
        tolerate=AllBrowsersBusy,
        timeout=config.browser_availability_timeout,
        throttle=config.browser_availability_throttle,
    )
Example #10
0
 def wait_for_jobs(self, *, expiry):
     cfg = config_for_module(__name__)
     throttle = cfg.delay_between_checks_for_parallel_suite_completion
     while self._running:
         if expiry and dependency(datetime).now() > expiry:
             self._kill_jobs()
             raise TimeoutError("Tests ran longer than the configured limit")
         sleep(throttle)
         self._prune()
def launch_local_browser():
    config = config_for_module(__name__)
    browser_name = config.use_browser
    if browser_name:
        browser_name = browser_name.lower()
    if browser_name in ("chrome", None):
        return launch_chrome()
    if "firefox" == browser_name:
        return launch_firefox()
    raise UnsupportedBrowser('"%s" is not supported' % browser_name)
def get_launch_function():
    config = config_for_module(__name__)
    location = config.browser_location
    if location:
        location = location.lower()
    if "browserstack" == location:
        return launch_browserstack_browser
    if "selenium_grid" == location:
        return launch_selenium_grid_browser
    return launch_local_browser
 def test_finds_config_file(self):
     key = "indicator"
     value = "squawk!"
     module_name = "parrot"
     module = FakeModule(context=self.context, name=module_name)
     module.add_config({key: value})
     self.load_module(module)
     config = config_for_module(module_name)
     expect(config).to(be_a(ModuleCfg))
     expect(config[key]).to(equal(value))
Example #14
0
 def _socket_timeout(self):
     config = config_for_module(__name__)
     timeout = config.http_client_socket_timeout
     if timeout == "":
         timeout = None
     if timeout is not None:
         try:
             timeout = float(timeout)
         except ValueError as e:
             raise TypeError("expected $CLIENT_SOCKET_TIMEOUT " f'("{timeout}") to be a number') from e
     return timeout
Example #15
0
    def test_uses_module_default_when_not_set_in_env(self):
        event = "spamorama"
        conf = config_for_module("questions_three.event_broker")
        retrieved = None

        def spy(*, run_id, **kwargs):
            nonlocal retrieved
            retrieved = run_id

        EventBroker.subscribe(event=event, func=spy)
        EventBroker.publish(event=event)
        expect(retrieved).to(equal(conf.test_run_id))
Example #16
0
 def publish(cls, *, event, event_time=None, **kwargs):
     conf = config_for_module(__name__)
     log = logger_for_module(__name__)
     run_id = conf.test_run_id
     if event_time is None:
         event_time = current_time()
     log.debug(event)
     if event in cls._subscribers.keys():
         for subscriber in cls._subscribers[event]:
             call_if_alive(subscriber,
                           event=event,
                           event_time=event_time,
                           run_id=run_id,
                           **kwargs)
def launch_selenium_grid_browser():
    config = config_for_module(__name__)
    hub_url = config.selenium_grid_hub_url
    if not hub_url:
        raise InvalidConfiguration(
            "Expected $SELENIUM_GRID_HUB_URL to be configured.")
    caps = {"browserName": config.use_browser}
    if config.use_browser:
        caps["browserName"] = config.use_browser
    browser_version = config.use_browser_version
    if browser_version:
        caps["version"] = browser_version
    return dependency(webdriver).Remote(command_executor=hub_url,
                                        desired_capabilities=caps)
 def save(self, *, artifact, path, filename, content_type):
     log = logger_for_module(__name__)
     bucket = config_for_module(__name__).s3_bucket_for_artifacts
     if not bucket:
         raise InvalidConfiguration("$S3_BUCKET_FOR_ARTIFACTS is not set")
     client = dependency(boto3).client("s3")
     kwargs = {
         "Bucket": bucket,
         "Key": _assemble_file_save_path(path, filename),
         "Body": artifact
     }
     if content_type:
         kwargs["ContentType"] = content_type
     log.debug(f"PUT {bucket}:{path}/{filename}")
     client.put_object(**kwargs)
Example #19
0
 def __init__(self):
     subscribe_event_handlers(self)
     config = config_for_module(__name__)
     log = logger_for_module(__name__)
     self._proxies = {}
     if config.http_proxy:
         proxy = config.http_proxy
         self._proxies["http"] = proxy
         log.debug(f"Using HTTP proxy {proxy}")
     if config.https_proxy:
         proxy = config.https_proxy
         self._proxies["https"] = proxy
         log.debug(f"(Using HTTPS proxy {proxy}")
     self._exception_callbacks = {}
     self._logger = logger_for_module(__name__)
     self._session = None
     self._persistent_headers = {}
     self._transcript = Transcript()
     self._verify_certs = config.https_verify_certs
     log.debug(f"Socket timeout: {self._socket_timeout()}")
Example #20
0
def launch_browserstack_browser():
    config = config_for_module(__name__)
    for name in ("browserstack_access_key", "browserstack_username"):
        if not config[name]:
            raise InvalidConfiguration('"%s" is not in the environment or a configuration file' % name)
    if require_browserstack_tunnel():
        tunnel = dependency(BrowserStackTunnel)()
    else:
        tunnel = None
    caps = {
        "browser": config.use_browser,
        "browserstack.debug": config.browserstack_set_debug,
        "browserstack.local": config.browserstack_set_local,
        "resolution": config.browserstack_screen_resolution,
        "os": config.browserstack_os,
        "os_version": config.browserstack_os_version,
    }
    browser_version = config.use_browser_version
    if browser_version:
        caps["browser_version"] = browser_version
    if tunnel is not None:
        caps["browserstack.localIdentifier"] = tunnel.local_identifier
    start = now()
    expiry = start + timedelta(seconds=config.browserstack_tunnel_timeout)
    while True:
        try:
            remote = dependency(webdriver).Remote(
                command_executor=insert_bs_credentials(url=config.browserstack_url), desired_capabilities=caps
            )
            break
        except WebDriverException as e:
            msg = str(e).lower()
            if "all parallel tests are currently in use" in msg:
                raise AllBrowsersBusy(msg)
            if "browserstack.local" in msg and now() <= expiry:
                continue
            raise
    remote.fullscreen_window()
    return remote
Example #21
0
def get_search_path():
    argv = dependency(sys.argv)
    if len(argv) > 1:
        return argv[1]
    return config_for_module(__name__).path_to_tests
def configured_reporters():
    conf = config_for_module(__name__)
    configured_names = conf.event_reporters.split(",")
    return [cls for cls in BUILT_IN_REPORTERS if cls.__name__ in configured_names]
def custom_reporter_filename():
    conf = config_for_module(__name__)
    return conf.custom_reporters_file
 def test_returns_empty_instance_when_module_has_no_config(self):
     module_name = "has_no_config"
     module = FakeModule(context=self.context, name=module_name)
     self.load_module(module)
     config = config_for_module(module_name)
     expect(config).to(be_a(ModuleCfg))
Example #25
0
def prepend_bs_credentials(netloc):
    config = config_for_module(__name__)
    return "%s:%s@%s" % (quote_plus(config.browserstack_username), quote_plus(config.browserstack_access_key), netloc)
 def test_none(self):
     key = "worries"
     name = self.add_module(values={key: None})
     actual = config_for_module(name)[key]
     expect(actual).to(be_a(type(None)))
Example #27
0
 def on_suite_ended(self, **kwargs):
     config = config_for_module(__name__)
     if not (self._failure_detected and config.suppress_browser_exit_on_failure):
         self._driver.quit()
def _assemble_file_save_path(path, filename):
    prefix_object = config_for_module(__name__).s3_prefix_object_name
    if prefix_object:
        return f"{prefix_object}/{path}/{filename}"
    return f"{path}/{filename}"
 def reports_path(self):
     config = config_for_module(__name__)
     return config.reports_path
Example #30
0
def require_browserstack_tunnel():
    conf = config_for_module(__name__)
    return "BrowserStack" == conf.browser_location and conf.browserstack_set_local