-
-
Notifications
You must be signed in to change notification settings - Fork 143
Remove graph config innards from defaultProps #515
Changes from 1 commit
3521da0
9e8f451
d4df7cc
071b11c
55f45d2
970c682
802a9c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from multiprocessing import Lock | ||
import time | ||
import json | ||
import re | ||
|
||
import flask | ||
import pandas as pd | ||
|
@@ -1184,6 +1185,54 @@ def on_click(n_clicks): | |
time.sleep(1) | ||
self.snapshot("Tabs 2 rendered ") | ||
|
||
# do some extra tests while we're here | ||
# and have access to Graph and plotly.js | ||
self.check_graph_config_shape() | ||
self.check_plotlyjs() | ||
|
||
def check_plotlyjs(self): | ||
# find plotly.js files in the dist folder, check that there's only one | ||
all_dist = os.listdir(dcc.__path__[0]) | ||
js_re = '^plotly-(.*)\.min\.js$' | ||
plotlyjs_dist = [fn for fn in all_dist if re.match(js_re, fn)] | ||
|
||
self.assertEqual(len(plotlyjs_dist), 1) | ||
|
||
# check that the version matches what we see in the page | ||
page_version = self.driver.execute_script('return Plotly.version;') | ||
dist_version = re.match(js_re, plotlyjs_dist[0]).groups()[0] | ||
self.assertEqual(page_version, dist_version) | ||
|
||
def check_graph_config_shape(self): | ||
config_schema = self.driver.execute_script( | ||
'return Plotly.PlotSchema.get().config;' | ||
) | ||
with open(os.path.join(dcc.__path__[0], 'metadata.json')) as meta: | ||
graph_meta = json.load(meta)['src/components/Graph.react.js'] | ||
config_prop_shape = graph_meta['props']['config']['type']['value'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kind of ugly to have to use |
||
|
||
ignored_config = [ | ||
'setBackground', | ||
'showSources', | ||
'logging', | ||
'globalTransforms', | ||
'role' | ||
] | ||
|
||
def crawl(schema, props): | ||
for prop_name in props: | ||
self.assertIn(prop_name, schema) | ||
|
||
for item_name, item in schema.items(): | ||
if item_name in ignored_config: | ||
continue | ||
|
||
self.assertIn(item_name, props) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently not testing anything about the props, just that the right keys exist. We could enhance this later to verify that their types match what's in the schema. Note that we could have put back in the deep defaults and used a similar framework to test that they match the schema, but I don't think that's a good idea. We'd still have the problem of a single override dropping the defaults - in principle picking up the right defaults again from plotly.js, but there could be subtle problems with this, or perhaps a user overrides the plotly.js version... I'd rather keep the looser coupling. |
||
if 'valType' not in item: | ||
crawl(item, props[item_name]['value']) | ||
|
||
crawl(config_schema, config_prop_shape) | ||
|
||
def test_tabs_without_value(self): | ||
app = dash.Dash(__name__) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how we ended up with 2 copies of plotly.js on master, 1.44.1 and 1.45.0... the associated PRs all seem to swap one file for another, maybe a mis-merge somewhere. But anyway this test will prevent that in the future.