pyani icon indicating copy to clipboard operation
pyani copied to clipboard

Add `try/except` around extraction to accommodate failing uncompression in `pyani download`

Open baileythegreen opened this issue 3 years ago • 3 comments

Fixes problem where failure to extract the contents of individual zip files from pyani download triggers a SystemExit.

Closes #383.

Please include a summary of the change and which issue is fixed. Please also include the motivation and context, and note the tests that apply to these changes.

Type of change

  • [x] Bug fix (non-breaking change that fixes an issue)
  • [ ] New feature (non-breaking change that adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • [ ] This change requires a documentation update
  • [ ] This is a documentation update

Action Checklist

  • [x] Work on a single issue/concept (if there are multiple separate issues to address, please use a separate pull request for each)
  • [ ] Fork the pyani repository under your own account (please allow write access for repository maintainers)
  • [x] Set up an appropriate development environment (please see CONTRIBUTING.md)
  • [x] Create a new branch with a short, descriptive name
  • [x] Work on this branch
    • [x] style guidelines have been followed
    • [x] new code is commented, especially in hard-to-understand areas
    • [ ] corresponding changes to documentation have been made
    • [ ] tests for the change have been added that demonstrate the fix or feature works
  • [x] Test locally with pytest -v non-passing code will not be merged
  • [x] Rebase against origin/master
  • [x] Check changes with flake8 and black before submission
  • [x] Commit branch
  • [x] Submit pull request, describing the content and intent of the pull request
  • [ ] Request a code review
  • [ ] Continue the discussion at Pull requests section in the pyani repository

baileythegreen avatar Mar 14 '22 23:03 baileythegreen

Codecov Report

Merging #385 (48119e4) into master (62949c4) will decrease coverage by 0.07%. The diff coverage is 58.33%.

@@            Coverage Diff             @@
##           master     #385      +/-   ##
==========================================
- Coverage   75.82%   75.74%   -0.08%     
==========================================
  Files          55       55              
  Lines        3747     3756       +9     
==========================================
+ Hits         2841     2845       +4     
- Misses        906      911       +5     

codecov[bot] avatar Mar 14 '22 23:03 codecov[bot]

Even with the custom exception class, the fact that I am handling the error means pytest does not recognise it as thrown if the test is called from the top of subcmd_download. Using download.exract_genomes() as the entry point might solve it, but will require the creation of several fixtures to pass as its parameters—and those fixtures will be basically identical to the return values of the mocked functions in mock_single_genome_dl.

I believe passing fixtures into mock functions (that use the monkeypatch fixture) is not really done, or I would abstract out the objects to avoid redundancy.

Currently, I have opted to write a unit test for download.extract_contigs(), the most proximal source of the raised Exception. This is rather straightfoward, as the error is not handled there, and the only inputs are two Paths. However, it means that the actual try/except blocks are flagged by codecov.

Should I pursue tests for those blocks?

baileythegreen avatar Mar 30 '22 12:03 baileythegreen

@widdowquinn Do you find the current state of testing for these changes sufficient, or would you want to see something else?

baileythegreen avatar Apr 29 '22 10:04 baileythegreen