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

Sarracenia __init__ unit test #730

Merged
merged 5 commits into from
Jul 26, 2023
Merged

Sarracenia __init__ unit test #730

merged 5 commits into from
Jul 26, 2023

Conversation

gcglinton
Copy link
Contributor

This test is pretty exhaustive, and probably overkill for the needs, but it's got 90% code coverage so that's pretty good.

There's some odd things that weren't able to provide coverage for though:

  • Message.dumps():
    • Couldn't generate anything that wasn't printable, and thus fail the try on line 451
  • Message.fromFileInfo():
    • It generates a new msg at every run, so couldn't get it to do the rename bits on lines 532-536. How sure how those are supposed to work
    • Messages never have the new_retrievePath key, so the if o.rename block on lines 543-547 throws a key error if it runs (there's a test case for that though)
    • Couldn't get the try on line 555 to fail no matter how many directories were striped, so the except never runs
  • Message.updatePaths():
    • The new_dir and new_file parameters are optional, but their concatenation on line 686 throws an error if they're not set (there's a test case for this too)
    • With new_dir effectively being mandatory, the ifs on lines 719 and 735 don't really work properly because they can never evaluate to True
  • "Extras" checking
    • It doesn't work because no way was found to emulate the packages being in a different state than they actually are on the system

Interesting bits/lessons learned when writing these tests:

  • Mocked some internal modules/methods/attributes in order to "trick" the code to trigger a certain behaviour
    • Lines 150 and 162 are replacing random.choice's return with None
    • Line 409 is faking being Windows for the following lines
    • Line 471 is faking urllib.request.urlopen's return as a static string, bypassing the need to actually do an HTTP request
  • Some method calls throw errors, and Pytest catches them properly (lines 317, 351, 443)
    • Could be good for doing doing input validation and such

This has about 90% coverage
Debugging tests wasn't working, and it's because generating code coverage while debugging breaks debugging.
Apparently it's not a standard module everywhere, so this is a workaround
Could also juse use SR3's filemetadata methods, as they handle things "nicely"
@petersilva
Copy link
Contributor

more tests always better than no tests... this is great! if there is something wrong, we can just fix it later...

@petersilva petersilva merged commit e401ab3 into MetPX:v03_wip Jul 26, 2023
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.

2 participants