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

Make tests more independent #5211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Make tests more independent #5211

wants to merge 2 commits into from

Conversation

mr-c
Copy link
Contributor

@mr-c mr-c commented Feb 13, 2025

Also fixes #3996

Changelog Entry

To be copied to the draft changelog by merger:

  • tests now load their data more flexibly

Reviewer Checklist

  • Make sure it is coming from issues/XXXX-fix-the-thing in the Toil repo, or from an external repo.
    • If it is coming from an external repo, make sure to pull it in for CI with:
      contrib/admin/test-pr otheruser theirbranchname issues/XXXX-fix-the-thing
      
    • If there is no associated issue, create one.
  • Read through the code changes. Make sure that it doesn't have:
    • Addition of trailing whitespace.
    • New variable or member names in camelCase that want to be in snake_case.
    • New functions without type hints.
    • New functions or classes without informative docstrings.
    • Changes to semantics not reflected in the relevant docstrings.
    • New or changed command line options for Toil workflows that are not reflected in docs/running/{cliOptions,cwl,wdl}.rst
    • New features without tests.
  • Comment on the lines of code where problems exist with a review comment. You can shift-click the line numbers in the diff to select multiple lines.
  • Finish the review with an overall description of your opinion.

Merger Checklist

  • Make sure the PR passed tests, including the Gitlab tests, for the most recent commit in its branch.
  • Make sure the PR has been reviewed. If not, review it. If it has been reviewed and any requested changes seem to have been addressed, proceed.
  • Merge with the Github "Squash and merge" feature.
    • If there are multiple authors' commits, add Co-authored-by to give credit to all contributing authors.
  • Copy its recommended changelog entry to the Draft Changelog.
  • Append the issue number in parentheses to the changelog entry.

@mr-c mr-c force-pushed the test_data_location branch 4 times, most recently from 4230cab to 65f9e71 Compare February 14, 2025 09:22
Copy link
Member

@adamnovak adamnovak left a comment

Choose a reason for hiding this comment

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

I want to know that this isn't able to ship arbitrary files that happen to be on disk in the builds before merging. But other than that, even though I think the design of get_data() might be able to be better, I think this is a clear improvement.

Comment on lines +6 to +8
include src/toil/test/docs/scripts/*
include src/toil/test/utils/ABCWorkflowDebug/sleep.yaml
include src/toil/test/utils/ABCWorkflowDebug/*
Copy link
Member

Choose a reason for hiding this comment

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

Are these implicitly scoped by what is in source control? Or will the wildcards potentially include things like editor swap files in the release?

Comment on lines +58 to +73
def get_data(filename: str) -> str:
"""Returns an absolute path for a file from this package."""
# normalizing path depending on OS or else it will cause problem when joining path
filename = os.path.normpath(filename)
filepath = None
# import ipdb; ipdb.set_trace()
try:
file_manager = ExitStack()
atexit.register(file_manager.close)
traversable = files("toil") / filename
filepath = file_manager.enter_context(as_file(traversable))
except ModuleNotFoundError:
pass
if not filepath or not os.path.isfile(filepath):
filepath = Path(os.path.dirname(__file__)) / ".." / ".." / ".." / filename
return str(filepath.resolve())
Copy link
Member

Choose a reason for hiding this comment

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

Should _projectRootPath() and ToilTest.rootDir be removed in favor of this as the One True Way to access test files? (And if this is the One True Way, the docstring should note that so we know nwver to not use this function.)

Should this maybe be a member of ToilTest so it doesn't need a separate import and more sensibly replaces self.rootDir references?

Also, if the source tree is laid out so that a CWL file references another file nearby, and I get_data("whatever.cwl"), does get_data() promise that the path it returns will have those nearby files from the source tree still available, without explicitly being asked for them?

Copy link
Member

Choose a reason for hiding this comment

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

Also, are we sure that the atexit trickery to defeat the context manager is worth it? I don't see many tests using more than 2 get_data() calls, so even if it was a context manager you had to be in for each file, the nesting wouldn't be that bad. If we had a way to say with get_datas(path1, path2, path3) as (file1, file2, file3): for any number of arguments we could limit the nesting without fighting the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New build system. setup.py is being deprecated.
2 participants