8000 Add support for image diff in headless chrome by mattpap · Pull Request #6595 · bokeh/bokeh · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:

install: scripts/ci/install:test
script: scripts/ci/test
addons:
chrome: stable
before_script:
- google-chrome-stable --no-sandbox --headless --remote-debugging-port=9222 &
env:
- GROUP=examples
- PYTHON=2.7
Expand Down
41 changes: 41 additions & 0 deletions bokehjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion bokehjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"esprima": "^4.0.0",
"escodegen": "^1.8.1",
"estraverse": "^4.2.0",
"chrome-remote-interface": "^0.25.5",
"@types/node": "^7.0.18",
"@types/mocha": "^2.2.41",
"@types/chai": "^3.5.2",
Expand All @@ -88,7 +89,8 @@
"@types/combine-source-map": "^0.8.0",
"convert-source-map": "^1.5.0",
"@types/convert-source-map": "^1.3.33",
"merge-source-map": "^1.0.4"
"merge-source-map": "^1.0.4",
"mkdirp": "^0.5.1"
},
"dependencies": {
"es6-weak-map": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"tests.plugins.image_diff",
"tests.plugins.jupyter_notebook",
"tests.plugins.file_server",
"tests.plugins.phantomjs_screenshot",
"tests.plugins.screenshot",
)


Expand Down
7 changes: 0 additions & 7 deletions tests/examples/collect_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

from ..plugins.utils import trace, green

import logging
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.INFO)

class Flags(object):
js = 1 << 0
file = 1 << 1
Expand Down Expand Up @@ -179,10 +176,6 @@ def upload_imgs(self):
def images_differ(self):
return self.pixels != 0

@property
def dimensions_differ(self):
return self.pixels == -1

def add_examples(list_of_examples, path, examples_dir, example_type=None, slow=None, skip=None, no_js=None, no_diff=None):
if path == '*':
example_path = examples_dir
Expand Down
4 changes: 1 addition & 3 deletions tests/examples/examples_report.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
{% if not skipped and not example.no_js %}
<a href="{{ example.img_path_or_url }}"><img class="thumbnail" src="{{ example.img_path_or_url }}"></img></a>
{% if not example.no_diff %}
{% if example.dimensions_differ %}
<div class="thumbnail">Dimensions differ</div>
{% elif example.images_differ %}
{% if example.images_differ %}
<a href="{{ example.diff_path_or_url }}"><img class="thumbnail" src="{{ example.diff_path_or_url }}"></img></a>
{% else %}
<div class="thumbnail">No diff</div>
Expand Down
3 changes: 0 additions & 3 deletions tests/examples/examples_report_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from .collect_examples import collect_examples, Flags

def pytest_addoption(parser):
parser.addoption(
"--notebook-phantom-wait", dest="notebook_phantom_wait", action="store", type=int, default=10,
help="How long should PhantomJS wait before taking a snapshot of a notebook (in seconds)")
parser.addoption(
"--output-cells", type=str, choices=['complain', 'remove', 'ignore'], default='complain',
help="what to do with notebooks' output cells")
Expand Down
40 changes: 14 additions & 26 deletions tests/examples/test_examples.py
67DE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from os.path import dirname, exists, split

from tests.plugins.utils import trace, info, fail, ok, red, warn, white
from tests.plugins.phantomjs_screenshot import get_phantomjs_screenshot
from tests.plugins.screenshot import get_screenshot
from tests.plugins.image_diff import image_diff

from bokeh.client import push_session
Expand Down Expand Up @@ -113,7 +113,7 @@ def _get_pdiff(example):

example.pixels = image_diff(diff_path, img_path, ref_path)
if example.pixels != 0:
comment = "dimensions don't match" if example.pixels == -1 else white("%.02f%%" % example.pixels) + " of pixels"
comment = white("%.02f%%" % example.pixels) + " of pixels"
warn("generated and reference images differ: %s" % comment)
else:
ok("generated and reference images match")
Expand All @@ -131,32 +131,23 @@ def _get_path_parts(path):
return parts


def _print_phantomjs_output(result):
def _print_webengine_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)
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 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")
for line in error['text'].split("\n"):
fail(line, label="JS")


def _assert_snapshot(example, url, example_type):
Expand All @@ -166,30 +157,27 @@ def _assert_snapshot(example, url, example_type):
height = 2000 if example_type == 'notebook' else 1000

local_wait = 100
global_wait = 30000
global_wait = 15000

start = time.time()
result = get_phantomjs_screenshot(url, screenshot_path, local_wait, global_wait, width, height)
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']
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" % global_wait))

if pytest.config.option.verbose:
_print_phantomjs_output(result)
_print_webengine_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))


Expand Down
Loading
0