Skip to content

Commit 181e427

Browse files
committed
Test fixes
1 parent ffc277d commit 181e427

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Diff for: packages/python/plotly/plotly/io/_templates.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def to_templated(fig, skip=("title", "text")):
390390
>>> templated_fig = pio.to_templated(fig)
391391
>>> templated_fig.layout.template
392392
layout.Template({
393-
'data': {}, 'layout': {'font': {'family': 'Courier', 'size': 20}}
393+
'layout': {'font': {'family': 'Courier', 'size': 20}}
394394
})
395395
>>> templated_fig
396396
Figure({
@@ -483,10 +483,17 @@ def to_templated(fig, skip=("title", "text")):
483483
trace_type_indexes[trace.type] = template_index + 1
484484

485485
# Remove useless trace arrays
486+
any_non_empty = False
486487
for trace_type in templated_fig.layout.template.data:
487488
traces = templated_fig.layout.template.data[trace_type]
488489
is_empty = [trace.to_plotly_json() == {"type": trace_type} for trace in traces]
489490
if all(is_empty):
490491
templated_fig.layout.template.data[trace_type] = None
492+
else:
493+
any_non_empty = True
494+
495+
# Check if we can remove the data altogether key
496+
if not any_non_empty:
497+
templated_fig.layout.template.data = None
491498

492499
return templated_fig

Diff for: packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_graph_objs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_old_class_names(self):
5252
# compat, so we basically just create a checkpoint with this test.
5353

5454
for class_name in OLD_CLASS_NAMES:
55-
self.assertIn(class_name, go.__dict__.keys())
55+
self.assertIsNotNone(getattr(go, class_name, None))
5656

5757
def test_title_as_string_layout(self):
5858
"""

Diff for: packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_instantiate_hierarchy.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class HierarchyTest(TestCase):
1818
def test_construct_datatypes(self):
1919
for datatypes_module in datatype_modules:
2020
module = importlib.import_module(datatypes_module)
21-
for name, obj in inspect.getmembers(module, inspect.isclass):
22-
if name.startswith("_"):
21+
for name in getattr(module, "__all__", []):
22+
obj = getattr(module, name)
23+
if name.startswith("_") or name[0].islower():
2324
continue
2425
try:
2526
v = obj()
@@ -29,7 +30,8 @@ def test_construct_datatypes(self):
2930
obj=obj, module=datatypes_module
3031
)
3132
)
32-
33+
raise
34+
print(module, name, obj)
3335
if obj.__module__ == "plotly.graph_objs._deprecations":
3436
self.assertTrue(isinstance(v, list) or isinstance(v, dict))
3537
obj()

Diff for: packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_move_layout_nested_properties(self):
195195
"layout": {
196196
"font": {"family": "Courier New"},
197197
"paper_bgcolor": "yellow",
198-
}
198+
},
199199
},
200200
"title": "Hello",
201201
}

0 commit comments

Comments
 (0)