Skip to content

Refactor archiver tests #1542

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

Merged
merged 4 commits into from
Mar 7, 2022
Merged

Refactor archiver tests #1542

merged 4 commits into from
Mar 7, 2022

Conversation

krivard
Copy link
Contributor

@krivard krivard commented Mar 2, 2022

Based on #1522

Description

Type of change (bug fix, new feature, etc), brief description, and motivation for these changes.

Archiver tests are a twisty maze of numbered csv files, each file testing a different corner case. The before, after, and expected .diff content is defined in different places in the code, sometimes multiple times. This approach is difficult to interpret without spending extensive time with the code, making it (1) difficult to update, (2) difficult to review, and (3) easy for errors or inconsistencies to creep in.

This PR refactors the archiver tests to:

  • collect information about each file together
  • only compute expected data once
  • name files with the corner case they test, so it's easier to keep track

Changelog

Itemize code/test/documentation changes and files added/removed.

  • test_archive.py: substantial refactor
    • Example class
    • Expecteds class
    • CSV_BEFORE, CSV_AFTER, various expected_csv[0-9]_diff definitions merged into a single CSVS dict
    • csv[0-9] converted to descriptive names eg "deleted" "added" "unchanged"
    • new global EXPECTEDS storing the filenames expected in various locations at different stages of archivediffing
    • repetitive manual lists of expected filenames converted in most cases to computational definitions based on the CSVS dict, with an assert check wherever changes to the test cases must be manually propagated to EXPECTEDS
    • ArchiveDifferTestlike class with centralized definitions of cache/export setup and final filtered exports check
    • File content spot-checks converted to exhaustive checks
    • TestArchiveDiffer, TestS3ArchiveDiffer, TestGitArchiveDiffer converted from CSV_BEFORE etc to CSVS and EXPECTEDS

Fixes

  • Working with tests should not feel like this:
    image

* collect information about each file together
* only compute expected data once
* name files with the corner case they test
Base automatically changed from dshem/fix-archiver to main March 2, 2022 18:13
@krivard krivard requested a review from dshemetov March 2, 2022 18:13
Copy link
Contributor

@dshemetov dshemetov 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 doing this, definitely overdue! Few minor suggestions, but overall looks great 🚀

Copy link
Contributor Author

@krivard krivard left a comment

Choose a reason for hiding this comment

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

this was excellent, thank you

@krivard krivard merged commit 15fe624 into main Mar 7, 2022
@krivard krivard deleted the krivard/refactor-archiver-tests branch March 7, 2022 18:51
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