Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Remove graph config innards from defaultProps #515

Merged
merged 7 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions dash_core_components/plotly-1.44.1.min.js

This file was deleted.

49 changes: 49 additions & 0 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from multiprocessing import Lock
import time
import json
import re

import flask
import pandas as pd
Expand Down Expand Up @@ -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)
Copy link
Collaborator Author

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.


# 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']
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of ugly to have to use metadata.json for this... I was hoping I could get this directly from the Graph component, but PropTypes seems to turn everything into a validation function, I don't see a way to get the input params back out.


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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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__)

Expand Down