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 _get_pdiff(example): img_path, ref_path, diff_path = example.img_path, example.ref_path, example.diff_path trace("generated image: " + img_path) ref = example.fetch_ref() if not ref: warn("reference image %s doesn't exist" % example.ref_url) else: _store_binary(ref_path, ref) trace("saved reference: " + ref_path) example.pixels = image_diff(diff_path, img_path, ref_path) if example.pixels != 0: comment = white("%.02f%%" % example.pixels) + " of pixels" warn("generated and reference images differ: %s" % comment) else: ok("generated and reference images match")
def _get_pdiff(example): img_path, ref_path, diff_path = example.img_path, example.ref_path, example.diff_path trace("generated image: " + img_path) ref = example.fetch_ref() if not ref: warn("reference image %s doesn't exist" % example.ref_url) else: ref_dir = dirname(ref_path) if not exists(ref_dir): os.makedirs(ref_dir) with open(ref_path, "wb") as f: f.write(ref) trace("saved reference: " + ref_path) example.pixels = image_diff(diff_path, img_path, ref_path) if example.pixels != 0: comment = white("%.02f%%" % example.pixels) + " of pixels" warn("generated and reference images differ: %s" % comment) else: ok("generated and reference images match")
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