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

refactor test_connect for new test suite #12191

Merged
merged 1 commit into from Sep 24, 2021

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented Sep 23, 2021

Provides mixins for TestCosmology to test the descriptors.
Now every cosmology will test that it can I/O.
Also the classes in connect.py have some extra tests built upon the more general tests that each cosmology runs.

Signed-off-by: Nathaniel Starkman (@nstarman) nstarkman@protonmail.com

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the Extra CI label.
  • Is a change log needed? If yes, did the change log check pass? If no, add the no-changelog-entry-needed label. If this is a manual backport, use the skip-changelog-checks label unless special changelog handling is necessary.
  • Is a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate backport-X.Y.x label(s) before merge.

@nstarman nstarman added this to the v5.0 milestone Sep 23, 2021
@nstarman nstarman added this to In progress in Cosmology, the Expansion via automation Sep 23, 2021
@pep8speaks
Copy link

pep8speaks commented Sep 23, 2021

Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style.

There are no PEP8 style issues with this pull request - thanks! 🎉

Comment last updated at 2021-09-24 21:06:23 UTC

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

This looks good. The one thing I feel is missing is good docstrings for the Mixin test classes, on what subclasses are supposed to define (the cosmo fixture?).

One thing I wondered was whether you are still sure no test is run twice - a disadvantage of this fairly complicated structure is that this is no longer obvious...

Anyway, I think the goal here is good and it looks all in order, so approving.

@@ -264,7 +264,7 @@ def __new__(cls, *args, **kwargs):

return self

def __init__(self, *args, name=None, meta=None, **kwargs):
def __init__(self, name=None, meta=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, good not to eat arguments without warning or error!


class TestReadWriteCosmology:
@pytest.fixture(scope="class", autouse=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't know about this one. Out of curiosity, any reason not to use setup_class and teardown_class? Are you avoiding those to avoid forcing super() calls when actually used as a mixin?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's mostly that.
And since these are "mixin" it helps keep the class orthogonal.

"""
Test writing from an instance and reading from that class.
This requires partial information.

.. todo::

generalize over all save formats for this test.
remove when fix method in super
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is addressed to yourself, so perhaps not relevant, but I would have no idea what it meant!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah. I haven't figured out how to do this in general. Modifying a dict is different than a table is different than a Model. I want to test reading from a class and having that class fill in missing information, but I need to figure out how to delete that information. So currently this test only runs on dicts.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not dire, which is why I'm leaving in a TODO, but it would be best to show the information inference works irrespective of the format.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I have a solution... you'll see it soonish 😆

Cosmology, the Expansion automation moved this from In progress to Reviewer approved Sep 24, 2021
@nstarman
Copy link
Member Author

nstarman commented Sep 24, 2021

This looks good. The one thing I feel is missing is good docstrings for the Mixin test classes, on what subclasses are supposed to define (the cosmo fixture?).

A good point! I'll add some documentation on that.
Yes, subclasses just need to define a cosmo fixture. Thankfully pytest remembers all the other fixtures in inherited methods.

One thing I wondered was whether you are still sure no test is run twice - a disadvantage of this fairly complicated structure is that this is no longer obvious...

I've tested this pretty thoroughly in other code. Long story short: pytest only runs code starting with test (case insensitive), but it will run a test suite twice if that code is imported into a different module. So a test test_core.TestThis imported into test_flrw.py will be run a second time. There is an easy way around this: rename the imported object, e.g. from .test_core import TestCosmology as CosmologyTest. CosmologyTest is not run again.
It's contents will be run when stuck into a subclass, but that's on purpose since the subclass provides a new cosmo fixture.

@nstarman nstarman added the 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Sep 24, 2021
Provides mixins for TestCosmology to test the descriptors

Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@nstarman nstarman merged commit e078885 into astropy:main Sep 24, 2021
Cosmology, the Expansion automation moved this from Reviewer approved to Done Sep 24, 2021
@nstarman nstarman deleted the cosmo_improve_connect_tests branch September 24, 2021 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cosmology Refactoring testing 💤 merge-when-ci-passes Do not use: We have auto-merge option now.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants