Skip to content

TST: added test to ensure subclasses of ExcelWriter don't add any public attributes #50097

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

Merged
merged 8 commits into from
Dec 12, 2022
12 changes: 12 additions & 0 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
register_writer,
)

# added for last test
Copy link
Member

Choose a reason for hiding this comment

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

This comment isn't needed

from pandas.io.excel._util import _writers


@pytest.fixture
def path(ext):
Expand Down Expand Up @@ -1353,3 +1356,12 @@ def test_excelwriter_fspath(self):
with tm.ensure_clean("foo.xlsx") as path:
with ExcelWriter(path) as writer:
assert os.fspath(writer) == str(path)

# testing that subclasses of ExcelWriter don't have public attributes (issue 49602)
Copy link
Member

Choose a reason for hiding this comment

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

Could you put this in the testing function?



@pytest.mark.parametrize("klass", _writers.values())
def test_subclass_attr(klass):
attrs_base = {name for name in dir(ExcelWriter) if not name.startswith("_")}
attrs_klass = {name for name in dir(klass) if not name.startswith("_")}
assert attrs_base.symmetric_difference(attrs_klass) == set()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert attrs_base.symmetric_difference(attrs_klass) == set()
assert not attrs_base.symmetric_difference(attrs_klass)