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

Conversation

catmar22
Copy link
Contributor

@catmar22 catmar22 commented Dec 6, 2022

@@ -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

@@ -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?

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)

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite IO Excel read_excel, to_excel labels Dec 8, 2022
@catmar22
Copy link
Contributor Author

catmar22 commented Dec 8, 2022

I am failing the pre-commit check and from what I saw in the results of the tests this time, I think it has to do with the import statement? Do you have any input on what the issue might be, ie did I put it in a bad spot based on certain code style/maintenance criteria? Or where I could look for further documentation on this?

@mroeschke
Copy link
Member

@catmar22 catmar22 requested a review from mroeschke December 12, 2022 04:47
@mroeschke mroeschke added this to the 2.0 milestone Dec 12, 2022
@mroeschke mroeschke merged commit 7b2dd38 into pandas-dev:main Dec 12, 2022
@mroeschke
Copy link
Member

Thanks @catmar22

@rhshadrach
Copy link
Member

Thanks @catmar22!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Excel read_excel, to_excel Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: Subclasses of ExcelWriter should not be allowed to add new public attributes
3 participants