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

Issue #402: Fix tests that fail as a result of running pytest with no flags #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyani/scripts/average_nucleotide_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@ def process_arguments(args: Optional[Namespace]) -> Namespace:
shows the version and exits.
"""
# Catch execution with no arguments
if len(sys.argv) == 1:
# But only for the `pyani` executable (`pytest` was also being caught here)
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why endswith() is used in preference to ==. What is your thinking, here?

Also, the pyani command would not executeaverage_nucleotide_identity.py - the command for this is average_nucleotide_identity.py (see this line), so should this not be testing for average_nucleotide_identity.py rather than pyani?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the == part, see my response below.

Also, the pyani command would not execute average_nucleotide_identity.py

Yes, you're right; that was a mistake on my part.

Copy link
Owner

Choose a reason for hiding this comment

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

So long as you make the change such that v0.2 tests for average_nucleotide_identity.py this part of the conversation can be resolved.

if len(sys.argv) == 1 and sys.argv[0].endswith("pyani"):
sys.stderr.write("pyani version: {0}\n".format(__version__))
raise SystemExit(0)

Expand Down
4 changes: 4 additions & 0 deletions pyani/scripts/pyani_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def run_main(argv: Optional[List[str]] = None) -> int:
sys.stderr.write(f"{VERSION_INFO}\n")
return 0

# If the command run is not pyani (e.g., `pytest`, then we
# don't want to apply pyani-specific checks)
if len(sys.argv) == 1 and not sys.argv[0].endswith("pyani"):
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why endswith() is used in preference to ==. What is your thinking, here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because sys.argv[0] in this case is not pyani, but:

/Users/baileythegreen/Software/miniconda3/envs/pyani_dev/bin/pyani.

The same goes for pytest above. I tried == first, and it failed.

Copy link
Owner

@widdowquinn widdowquinn Jun 20, 2022

Choose a reason for hiding this comment

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

I see. It would be more robust to either (i) treat sys.argv[0] as a Path object and test for equality using the .name attribute, or (ii) .split("/") the passed path and test the last element in the resulting collection. Using .endswith() does give a True value with the case you want, but also in cases where the executable is not simply pyani (or pytest, in the case where you'r echecking for that):

>>> from pathlib import Path
>>> pyani_path = "/my/path/to/pyani"
>>> notpyani_path = "/my/path/to/notpyani"
>>> Path(pyani_path).name
'pyani'
>>> Path(notpyani_path).name
'notpyani'
>>> pyani_path.split("/")[-1]
'pyani'
>>> notpyani_path.split("/")[-1]
'notpyani'
>>> pyani_path.endswith("pyani")
True
>>> notpyani_path.endswith("pyani")
True

Copy link
Contributor Author

@baileythegreen baileythegreen Jun 20, 2022

Choose a reason for hiding this comment

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

I mentioned in our last meeting that I'd thought of a better way to do it, and I think I said that was using a Path() object; you said you thought not testing for pytest specifically would be better—and I thought part of the implication there was you didn't want Path() used.

I must have misunderstood; I can of course use Path() and test for whether the program is pyani, or not.

pass
# Catch requests for citation and version information
if sys.argv[1].startswith("-"):
if args.citation:
Expand Down