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

Unit tests for step.save and step.skip #197

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

emolter
Copy link
Collaborator

@emolter emolter commented Oct 10, 2024

This PR adds the unit tests from #190 as it looks like that PR is likely to be withdrawn, at least for the time being, but the unit tests are still relevant to the main branch.

Tasks

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • run regression tests with this branch installed ("git+https://github.com/<fork>/stpipe@<branch>")
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.misc.rst: infrastructure or miscellaneous change

@emolter emolter requested a review from a team as a code owner October 10, 2024 19:58
@emolter emolter added the no-changelog-entry-needed does not require an entry in `CHANGES.rst` label Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.94%. Comparing base (5efae61) to head (f6e2a84).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #197      +/-   ##
==========================================
+ Coverage   73.29%   76.94%   +3.65%     
==========================================
  Files          25       25              
  Lines        1917     1917              
==========================================
+ Hits         1405     1475      +70     
+ Misses        512      442      -70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emolter emolter mentioned this pull request Oct 10, 2024
7 tasks
return None


def test_save(tmp_cwd):
Copy link
Collaborator

@braingram braingram Jan 23, 2025

Choose a reason for hiding this comment

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

To check I'm following, does this test, test_skip and test_save_list aim to test the save_results spec feature? This wasn't clear to me when first looking at the test names/setup.

If this is the case would you add docstring and/or rename the tests to document they're testing save_results?

Comment on lines +452 to +453
with open(fname, "w") as f:
f.write(f"{path}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
with open(fname, "w") as f:
f.write(f"{path}")
with open(fname, "w") as f:
f.write(f"{path}")

Any reason to not use path as the filename to make the test more representative of a typical step?

Comment on lines +528 to +539
@pytest.mark.xfail(
reason="Looping over models only works for list and tuple. This should be fixed."
)
def test_save_container(tmp_cwd, model_list):
"""ensure list-like save still works for non-list sequence"""
container = SimpleContainer(model_list)
step = StepWithModel()
step.run(container)
for i in range(3):
assert (tmp_cwd / f"test{i}-saved.txt").exists()


Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@pytest.mark.xfail(
reason="Looping over models only works for list and tuple. This should be fixed."
)
def test_save_container(tmp_cwd, model_list):
"""ensure list-like save still works for non-list sequence"""
container = SimpleContainer(model_list)
step = StepWithModel()
step.run(container)
for i in range(3):
assert (tmp_cwd / f"test{i}-saved.txt").exists()

My vote is for making an issue/ticket for this instead of adding a known failing test. For the issue perhaps you would add some details about how this fails (does it throw an exception, overwrite files, not save?).

assert (tmp_cwd / f"test{i}-saved.txt").exists()


def test_skip_container(tmp_cwd, model_list):
Copy link
Collaborator

Choose a reason for hiding this comment

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

To confirm, there are no unit tests that currently test that Step.skip skips a step (for any input)? I'm failing to find any.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together. I left a few comments/suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-entry-needed does not require an entry in `CHANGES.rst`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants