Skip to content
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

prevent the creation of new px.default properties at run time #2183

Merged
merged 7 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 11 additions & 0 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@


class PxDefaults(object):
__slots__ = [
"template",
"width",
"height",
"color_discrete_sequence",
"color_continuous_scale",
"symbol_sequence",
"line_dash_sequence",
"size_max",
]

def __init__(self):
self.template = None
self.width = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import plotly.express as px
import numpy as np
import pytest


def test_scatter():
Expand Down Expand Up @@ -232,3 +233,9 @@ def assert_orderings(days_order, days_check, times_order, times_check):
for days in permutations(df["day"].unique()):
for times in permutations(df["time"].unique()):
assert_orderings(days, days, times, times)


def check_permissive_defaults():
Copy link
Contributor

Choose a reason for hiding this comment

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

I think your function should be called test_something so that pytest catches it in the test suite (otherwise it will consider it a helper function). You can verify this by executing locally pytest in your machine (for example in the same directory, pytest -v test_px.py and check whether the new function appears). Maybe I'm wrong but please check :-).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right about tests needing to start with test in order to be picked up by pytest.

After modifying to above code, the output of running pytest -v test_px.py is:

test_px.py::test_scatter PASSED
test_px.py::test_custom_data_scatter PASSED
test_px.py::test_labels PASSED
test_px.py::test_px_templates PASSED
test_px.py::test_orthogonal_orderings PASSED
test_px.py::test_permissive_defaults PASSED

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome!

msg = "AttributeError: 'PxDefaults' object has no attribute 'should_not_work'"
with pytest.raises(AttributeError, match=msg):
px.defaults.should_not_work = "test"