-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Props blacklist #753
Merged
Merged
Props blacklist #753
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8cc1d2e
remove MutableMapping inheritance from base Component
alexcjohnson bf26213
underscore traverse(_with_paths) methods of base Component
alexcjohnson 6102bf0
more robust path to local test files in test_base_component
alexcjohnson e8ff4f4
blacklist the attrs we need in Py from being component props
alexcjohnson 8432239
allow access of "protected" _traverse methods
alexcjohnson f0cec2f
changelog for props-blacklist
alexcjohnson e813a1f
use assert in new prop blacklist tests
alexcjohnson 64388b4
forbidden_props -> reserved_words, and include `_.*`
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from collections import OrderedDict | ||
import collections | ||
import inspect | ||
import json | ||
import os | ||
|
@@ -8,8 +7,16 @@ | |
import plotly | ||
|
||
from dash.development.base_component import Component | ||
from dash.development._py_components_generation import generate_class_string, generate_class_file, generate_class, \ | ||
create_docstring, prohibit_events, js_to_py_type | ||
from dash.development._py_components_generation import ( | ||
generate_class_string, | ||
generate_class_file, | ||
generate_class, | ||
create_docstring, | ||
prohibit_events, | ||
js_to_py_type | ||
) | ||
|
||
_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
Component._prop_names = ('id', 'a', 'children', 'style', ) | ||
Component._type = 'TestComponent' | ||
|
@@ -85,8 +92,9 @@ def test_get_item_with_nested_children_two_branches(self): | |
|
||
def test_get_item_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501 | ||
c, c1, c2, c3, c4, c5 = nested_tree() | ||
keys = [k for k in c] | ||
self.assertEqual( | ||
list(c.keys()), | ||
keys, | ||
[ | ||
'0.0', | ||
'0.1', | ||
|
@@ -135,15 +143,16 @@ def test_set_item_with_nested_children_with_mixed_strings_and_without_lists(self | |
|
||
def test_del_item_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501 | ||
c = nested_tree()[0] | ||
for key in reversed(list(c.keys())): | ||
keys = reversed([k for k in c]) | ||
for key in keys: | ||
c[key] | ||
del c[key] | ||
with self.assertRaises(KeyError): | ||
c[key] | ||
|
||
def test_traverse_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501 | ||
c, c1, c2, c3, c4, c5 = nested_tree() | ||
elements = [i for i in c.traverse()] | ||
elements = [i for i in c._traverse()] | ||
self.assertEqual( | ||
elements, | ||
c.children + [c3] + [c2] + c2.children | ||
|
@@ -153,19 +162,12 @@ def test_traverse_with_tuples(self): # noqa: E501 | |
c, c1, c2, c3, c4, c5 = nested_tree() | ||
c2.children = tuple(c2.children) | ||
c.children = tuple(c.children) | ||
elements = [i for i in c.traverse()] | ||
elements = [i for i in c._traverse()] | ||
self.assertEqual( | ||
elements, | ||
list(c.children) + [c3] + [c2] + list(c2.children) | ||
) | ||
|
||
def test_iter_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501 | ||
c = nested_tree()[0] | ||
keys = list(c.keys()) | ||
# get a list of ids that __iter__ provides | ||
iter_keys = [i for i in c] | ||
self.assertEqual(keys, iter_keys) | ||
|
||
def test_to_plotly_json_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501 | ||
c = nested_tree()[0] | ||
Component._namespace | ||
|
@@ -244,17 +246,6 @@ def test_get_item_raises_key_if_id_doesnt_exist(self): | |
with self.assertRaises(KeyError): | ||
c3['0'] | ||
|
||
def test_equality(self): | ||
# TODO - Why is this the case? How is == being performed? | ||
# __eq__ only needs __getitem__, __iter__, and __len__ | ||
self.assertTrue(Component() == Component()) | ||
self.assertTrue(Component() is not Component()) | ||
|
||
c1 = Component(id='1') | ||
c2 = Component(id='2', children=[Component()]) | ||
self.assertTrue(c1 == c2) | ||
self.assertTrue(c1 is not c2) | ||
|
||
def test_set_item(self): | ||
c1a = Component(id='1', children='Hello world') | ||
c2 = Component(id='2', children=c1a) | ||
|
@@ -450,6 +441,9 @@ def test_len(self): | |
])), 3) | ||
|
||
def test_iter(self): | ||
# The mixin methods from MutableMapping were cute but probably never | ||
# used - at least not by us. Test that they're gone | ||
|
||
# keys, __contains__, items, values, and more are all mixin methods | ||
# that we get for free by inheriting from the MutableMapping | ||
# and behave as according to our implementation of __iter__ | ||
|
@@ -469,40 +463,37 @@ def test_iter(self): | |
Component(children=[Component(id='8')]), | ||
] | ||
) | ||
# test keys() | ||
keys = [k for k in list(c.keys())] | ||
self.assertEqual(keys, ['2', '3', '4', '5', '6', '7', '8']) | ||
self.assertEqual([i for i in c], keys) | ||
|
||
# test values() | ||
components = [i for i in list(c.values())] | ||
self.assertEqual(components, [c[k] for k in keys]) | ||
mixins = ['clear', 'get', 'items', 'keys', 'pop', 'popitem', | ||
'setdefault', 'update', 'values'] | ||
|
||
for m in mixins: | ||
self.assertFalse(hasattr(c, m), m) | ||
|
||
keys = ['2', '3', '4', '5', '6', '7', '8'] | ||
|
||
# test __iter__() | ||
for k in keys: | ||
# test __contains__() | ||
self.assertTrue(k in c) | ||
# test __getitem__() | ||
self.assertEqual(c[k].id, k) | ||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# test __items__ | ||
items = [i for i in list(c.items())] | ||
self.assertEqual(list(zip(keys, components)), items) | ||
# test __iter__() | ||
keys2 = [] | ||
for k in c: | ||
keys2.append(k) | ||
self.assertIn(k, keys) | ||
|
||
def test_pop(self): | ||
c2 = Component(id='2') | ||
c = Component(id='1', children=c2) | ||
c2_popped = c.pop('2') | ||
self.assertTrue('2' not in c) | ||
self.assertTrue(c2_popped is c2) | ||
self.assertEqual(len(keys), len(keys2)) | ||
|
||
|
||
class TestGenerateClassFile(unittest.TestCase): | ||
def setUp(self): | ||
json_path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', 'metadata_test.json') | ||
json_path = os.path.join(_dir, 'metadata_test.json') | ||
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. So that you can run the tests from any working directory, not just the repo root. |
||
with open(json_path) as data_file: | ||
json_string = data_file.read() | ||
data = json\ | ||
.JSONDecoder(object_pairs_hook=collections.OrderedDict)\ | ||
.JSONDecoder(object_pairs_hook=OrderedDict)\ | ||
.decode(json_string) | ||
self.data = data | ||
|
||
|
@@ -537,9 +528,7 @@ def setUp(self): | |
self.written_class_string = f.read() | ||
|
||
# The expected result for both class string and class file generation | ||
expected_string_path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', 'metadata_test.py' | ||
) | ||
expected_string_path = os.path.join(_dir, 'metadata_test.py') | ||
with open(expected_string_path, 'r') as f: | ||
self.expected_class_string = f.read() | ||
|
||
|
@@ -567,12 +556,11 @@ def test_class_file(self): | |
|
||
class TestGenerateClass(unittest.TestCase): | ||
def setUp(self): | ||
path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', 'metadata_test.json') | ||
path = os.path.join(_dir, 'metadata_test.json') | ||
with open(path) as data_file: | ||
json_string = data_file.read() | ||
data = json\ | ||
.JSONDecoder(object_pairs_hook=collections.OrderedDict)\ | ||
.JSONDecoder(object_pairs_hook=OrderedDict)\ | ||
.decode(json_string) | ||
self.data = data | ||
|
||
|
@@ -583,14 +571,11 @@ def setUp(self): | |
namespace='TableComponents' | ||
) | ||
|
||
path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', | ||
'metadata_required_test.json' | ||
) | ||
path = os.path.join(_dir, 'metadata_required_test.json') | ||
with open(path) as data_file: | ||
json_string = data_file.read() | ||
required_data = json\ | ||
.JSONDecoder(object_pairs_hook=collections.OrderedDict)\ | ||
.JSONDecoder(object_pairs_hook=OrderedDict)\ | ||
.decode(json_string) | ||
self.required_data = required_data | ||
|
||
|
@@ -756,12 +741,11 @@ def test_required_props(self): | |
|
||
class TestMetaDataConversions(unittest.TestCase): | ||
def setUp(self): | ||
path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', 'metadata_test.json') | ||
path = os.path.join(_dir, 'metadata_test.json') | ||
with open(path) as data_file: | ||
json_string = data_file.read() | ||
data = json\ | ||
.JSONDecoder(object_pairs_hook=collections.OrderedDict)\ | ||
.JSONDecoder(object_pairs_hook=OrderedDict)\ | ||
.decode(json_string) | ||
self.data = data | ||
|
||
|
@@ -940,12 +924,11 @@ def assert_docstring(assertEqual, docstring): | |
|
||
class TestFlowMetaDataConversions(unittest.TestCase): | ||
def setUp(self): | ||
path = os.path.join( | ||
'tests', 'unit', 'dash', 'development', 'flow_metadata_test.json') | ||
path = os.path.join(_dir, 'flow_metadata_test.json') | ||
with open(path) as data_file: | ||
json_string = data_file.read() | ||
data = json\ | ||
.JSONDecoder(object_pairs_hook=collections.OrderedDict)\ | ||
.JSONDecoder(object_pairs_hook=OrderedDict)\ | ||
.decode(json_string) | ||
self.data = data | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Kind of a nice side effect, IMO, that components are now no longer always equal to each other - though I don't know why this would come up...