def _run_in_browser(example, url, verbose=False): start = time.time() result = run_in_chrome(url) end = time.time() info("Example rendered in %s" % white("%.3fs" % (end - start))) success = result["success"] timeout = result["timeout"] errors = result["errors"] state = result["state"] image = result["image"] no_errors = len(errors) == 0 if timeout: warn("%s %s" % (red("TIMEOUT:"), "bokehjs did not finish")) if verbose: _print_webengine_output(result) assert success, "%s failed to load" % example.relpath has_image = image is not None has_state = state is not None has_baseline = example.has_baseline baseline_ok = True if not has_state: fail("no state data was produced for comparison with the baseline") else: new_baseline = _create_baseline(state) example.store_baseline(new_baseline) if not has_baseline: fail("%s baseline doesn't exist" % example.baseline_path) else: result = example.diff_baseline() if result is not None: baseline_ok = False fail("BASELINE DOESN'T MATCH (make sure to update baselines before running tests):") for line in result.split("\n"): fail(line) example.store_img(image["data"]) if example.no_diff: warn("skipping image diff for %s" % example.relpath) elif not has_image: fail("no image data was produced for comparison with the reference image") assert no_errors, "%s failed with %d errors" % (example.relpath, len(errors)) assert has_state, "%s didn't produce state data" % example.relpath assert has_baseline, "%s doesn't have a baseline" % example.relpath assert baseline_ok, "%s's baseline differs" % example.relpath
def _print_webengine_output(result): errors = result['errors'] messages = result['messages'] for message in messages: level = message['level'] text = message['text'] url = message['url'] line = message['line'] col = message['col'] msg = "{%s} %s:%s:%s %s" % (level, url, line, col, text) info(msg, label="JS") for error in errors: for line in error['text'].split("\n"): fail(line, label="JS")
def _print_webengine_output(result: JSResult) -> None: errors = result['errors'] messages = result['messages'] for message in messages: level = message['level'] text = message['text'] url = message['url'] line = message['line'] col = message['col'] msg = "{%s} %s:%s:%s %s" % (level, url, line, col, text) info(msg, label="JS") for error in errors: _url = error["url"] if _url is not None: fail(f"@{_url}", label="JS") for _line in error['text'].split("\n"): fail(_line, label="JS")
def upload_file_to_s3(file_path, s3_filename, content_type="text/html", extra_message=None): """ Uploads a file to bokeh-travis s3 bucket. """ conn = connect_to_s3() upload = conn is not None try: with open(file_path, "rb") as f: contents = f.read() except OSError: fail("Upload was requested but file %s was not available." % file_path) upload = False if __version__.endswith("-dirty"): fail("Uploads are not permitted when working directory is dirty.") fail("Make sure that __version__ doesn't contain -dirty suffix.") upload = False if upload: bucket = conn.get_bucket(S3_BUCKET) key = S3Key(bucket, s3_filename) key.set_metadata("Content-Type", content_type) key.set_contents_from_string(contents, policy="public-read") url = join(S3_URL, s3_filename) if extra_message is not None: ok("%s | Access upload at: %s" % (extra_message, url)) else: trace("Access upload at: %s" % url)
def _run_in_browser(engine, url, local_wait=None, global_wait=None): """ wait is in milliseconds """ cmd = engine + [url] if local_wait is not None: cmd += [str(local_wait)] if global_wait is not None: cmd += [str(global_wait)] trace("Running command: %s" % " ".join(cmd)) env = os.environ.copy() env["NODE_PATH"] = join(TOP_PATH, 'bokehjs', 'node_modules') try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) except OSError as e: fail("Failed to run: %s" % " ".join(cmd)) fail(str(e)) sys.exit(1) (stdout, stderr) = proc.communicate() if proc.returncode != 0: output = stderr.decode("utf-8") fail(output) sys.exit(1) output = stdout.decode("utf-8") return json.loads(output)
def _get_screenshot(engine, url, screenshot_path, local_wait, global_wait, width, height): """ wait is in milliseconds """ cmd = engine + [url, screenshot_path, str(local_wait), str(global_wait), str(width), str(height)] trace("Running command: %s" % " ".join(cmd)) env = os.environ.copy() env["NODE_PATH"] = join(TOP_PATH, 'bokehjs', 'node_modules') try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) proc.wait() except OSError as e: fail("Failed to run: %s" % " ".join(cmd)) fail(str(e)) sys.exit(1) if proc.returncode != 0: output = proc.stderr.read().decode("utf-8") fail(output) sys.exit(1) output = proc.stdout.read().decode("utf-8") return json.loads(output)
def connect_to_s3(): """ Returns the connection object or None if connection failed. """ try: return boto.connect_s3() except NoAuthHandlerFound: fail("Upload was requested but could not connect to S3.") fail("This is expected if you are an external contributor submitting a PR to Bokeh.") fail("This could also happen if S3 credentials are not available on the machine where this test is running.") return None
def connect_to_s3(): ''' Return the connection object or None if connection failed. ''' try: # calling_format due to https://github.com/boto/boto/issues/2836 from boto.s3.connection import OrdinaryCallingFormat return boto.connect_s3(calling_format=OrdinaryCallingFormat()) except NoAuthHandlerFound: fail("Upload was requested but could not connect to S3.") fail("This is expected if you are an external contributor submitting a PR to Bokeh.") fail("This could also happen if S3 credentials are not available on the machine where this test is running.") return None
def connect_to_s3(): """ Returns the connection object or None if connection failed. """ try: return boto.connect_s3() except NoAuthHandlerFound: fail("Upload was requested but could not connect to S3.") fail( "This is expected if you are an external contributor submitting a PR to Bokeh." ) fail( "This could also happen if S3 credentials are not available on the machine where this test is running." ) return None
def connect_to_s3(): ''' Return the connection object or None if connection failed. ''' try: # calling_format due to https://github.com/boto/boto/issues/2836 from boto.s3.connection import OrdinaryCallingFormat return boto.connect_s3(calling_format=OrdinaryCallingFormat()) except NoAuthHandlerFound: fail("Upload was requested but could not connect to S3.") fail( "This is expected if you are an external contributor submitting a PR to Bokeh." ) fail( "This could also happen if S3 credentials are not available on the machine where this test is running." ) return None
def _run_in_browser(example, url, verbose=False): start = time.time() result = run_in_chrome(url) end = time.time() info("Example rendered in %s" % white("%.3fs" % (end - start))) success = result["success"] timeout = result["timeout"] errors = result["errors"] state = result["state"] image = result["image"] no_errors = len(errors) == 0 if timeout: warn("%s %s" % (red("TIMEOUT:"), "bokehjs did not finish")) if verbose: _print_webengine_output(result) assert success, "%s failed to load" % example.relpath has_image = image is not None has_state = state is not None has_baseline = example.has_baseline baseline_ok = True if not has_state: fail("no state data was produced for comparison with the baseline") else: new_baseline = _create_baseline(state) example.store_baseline(new_baseline) if not has_baseline: fail("%s baseline doesn't exist" % example.baseline_path) else: result = example.diff_baseline() if result is not None: baseline_ok = False fail("BASELINE DOESN'T MATCH (make sure to update baselines before running tests):") for line in result.split("\n"): fail(line) example.store_img(image["data"]) ref = example.fetch_ref() if not ref: warn("reference image %s doesn't exist" % example.ref_url) if example.no_diff: warn("skipping image diff for %s" % example.relpath) elif not has_image: fail("no image data was produced for comparison with the reference image") elif ref: pixels = example.image_diff() if pixels != 0: comment = white("%.02f%%" % pixels) + " of pixels" warn("generated and reference images differ: %s" % comment) else: ok("generated and reference images match") assert no_errors, "%s failed with %d errors" % (example.relpath, len(errors)) assert has_state, "%s didn't produce state data" % example.relpath assert has_baseline, "%s doesn't have a baseline" % example.relpath assert baseline_ok, "%s's baseline differs" % example.relpath