def _print_phantomjs_output(result): errors = result['errors'] messages = result['messages'] resources = result['resources'] for message in messages: msg = message['msg'] line = message.get('line') source = message.get('source') if source and line: msg = "%s:%s: %s" % (source, line, msg) info(msg, label="JS") for resource in resources: fail(resource['errorString'], label="JS") for error in errors: fail(error['msg'], label="JS") for item in error['trace']: file = item['file'] line = item['line'] if file and line: fail(" %s: %d" % (file, line), label="JS")
def test_file_examples(file_example, example, report): if example.is_skip: pytest.skip("skipping %s" % example.relpath) (status, duration, out, err) = _run_example(example) info("Example run in %s" % white("%.3fs" % duration)) for line in out.split("\n"): if len(line) == 0 or line.startswith("Wrote "): continue info(line, label="PY") for line in err.split("\n"): if len(line) == 0: continue warn(line, label="PY") assert status != "timeout", "%s timed out" % example.relpath assert status == 0, "%s failed to run (exit code %s)" % (example.relpath, status) if example.no_js: if not pytest.config.option.no_js: warn("skipping bokehjs for %s" % example.relpath) else: _assert_snapshot(example, "file://%s.html" % example.path_no_ext, 'file') if example.no_diff: warn("skipping image diff for %s" % example.relpath) else: _get_pdiff(example)
def _assert_snapshot(example, url, example_type): screenshot_path = example.img_path height = 2000 if example_type == 'notebook' else 1000 wait = 30000 start = time.time() result = get_phantomjs_screenshot(url, screenshot_path, 1000, wait, 1000, height) end = time.time() info("Example rendered in %s" % white("%.3fs" % (end - start))) success = result['success'] timeout = result['timeout'] errors = result['errors'] resources = result['resources'] no_errors = len(errors) == 0 no_resources = len(resources) == 0 if timeout: warn("%s: %s" % (red("TIMEOUT: "), "bokehjs did not finish in %s ms" % wait)) if pytest.config.option.verbose: _print_phantomjs_output(result) assert success, "%s failed to load" % example.relpath assert no_resources, "%s failed with %d missing resources" % (example.relpath, len(resources)) assert no_errors, "%s failed with %d errors" % (example.relpath, len(errors))
def _assert_snapshot(example, url, example_type): screenshot_path = example.img_path height = 2000 if example_type == 'notebook' else 1000 wait = 30000 start = time.time() result = get_phantomjs_screenshot(url, screenshot_path, 1000, wait, 1000, height) end = time.time() info("Example rendered in %s" % white("%.3fs" % (end - start))) success = result['success'] timeout = result['timeout'] errors = result['errors'] resources = result['resources'] no_errors = len(errors) == 0 no_resources = len(resources) == 0 if timeout: warn("%s: %s" % (red("TIMEOUT: "), "bokehjs did not finish in %s ms" % wait)) if pytest.config.option.verbose: _print_phantomjs_output(result) assert success, "%s failed to load" % example.relpath assert no_resources, "%s failed with %d missing resources" % ( example.relpath, len(resources)) assert no_errors, "%s failed with %d errors" % (example.relpath, len(errors))
def _assert_snapshot(example, url, example_type): screenshot_path = example.img_path width = 1000 height = 2000 if example_type == 'notebook' else 1000 local_wait = 100 global_wait = 15000 start = time.time() result = get_screenshot(url, screenshot_path, local_wait, global_wait, width, height) end = time.time() info("Example rendered in %s" % white("%.3fs" % (end - start))) success = result['success'] timeout = result['timeout'] errors = result['errors'] no_errors = len(errors) == 0 if timeout: warn("%s %s" % (red("TIMEOUT:"), "bokehjs did not finish in %s ms" % global_wait)) if pytest.config.option.verbose: _print_webengine_output(result) assert success, "%s failed to load" % example.relpath assert no_errors, "%s failed with %d errors" % (example.relpath, len(errors))
def _print_phantomjs_output(result): errors = result['errors'] messages = result['messages'] resources = result['resources'] for message in messages: msg = message['msg'] line = message.get('line') source = message.get('source') if source and line: msg = "%s:%s: %s" % (source, line, msg) info(msg, label="JS") # Process resources for resource in resources: url = resource['url'] if url.endswith(".png"): ok("%s: %s (%s)" % (url, yellow(resource['status']), resource['statusText'])) else: fail("Resource error:: %s: %s (%s)" % (url, red(resource['status']), resource['statusText']), label="JS") # You can have a successful test, and still have errors reported, so not failing here. for error in errors: fail(error['msg'], label="JS") for item in error['trace']: file = item['file'] line = item['line'] if file and line: fail(" %s: %d" % (file, line), label="JS")
def _get_reference_image_from_s3(example, diff): example_path = relpath(splitext(example)[0], example_dir) ref_loc = join(diff, example_path + ".png") ref_url = join(S3_URL, ref_loc) response = requests.get(ref_url) if not response.ok: info("reference image %s doesn't exist" % ref_url) return None return response.content
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 _get_pdiff(example, diff): test_png, ref_png, diff_png = get_example_pngs(example, diff) info("generated image: " + test_png) retrieved_reference_image = _get_reference_image_from_s3(example, diff) if retrieved_reference_image: ref_png_path = dirname(ref_png) if not exists(ref_png_path): os.makedirs(ref_png_path) with open(ref_png, "wb") as f: f.write(retrieved_reference_image) info("saved reference: " + ref_png) code = process_image_diff(diff_png, test_png, ref_png) if code != 0: warn("generated and reference images differ") warn("diff: " + diff_png) else: ok("generated and reference images match")