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

Refactor check module and associated tests #202

Merged
merged 9 commits into from
Mar 9, 2023

Conversation

jherland
Copy link
Member

@jherland jherland commented Mar 6, 2023

Mostly just moving code around to make our module structure reflect recent changes in our core logic. Also, more parametrized tests!

  • settings: Remove redundant/nested mutually exclusive argument group
  • test_compare_imports_to_dependencies: Tests for resolve_dependencies()
  • check: Refactor compare_imports_to_dependencies() into two functions
  • main: Call new functions instead of compare_imports_to_dependencies()
  • test_compare_imports_to_dependencies: Refactor and add tests
  • check: Remove compare_imports_to_dependencies()
  • Refactor all package-mapping code into a new fawltydeps.packages module

@jherland jherland self-assigned this Mar 6, 2023
@jherland jherland requested review from mknorps and Nour-Mws March 6, 2023 08:00
Base automatically changed from jherland/nix-shell-fix-python37-take2 to main March 6, 2023 12:33
@jherland jherland force-pushed the jherland/refactor-compare-code branch from 6ec216f to 7b7b861 Compare March 6, 2023 12:35
@jherland jherland mentioned this pull request Mar 7, 2023
5 tasks
Copy link
Collaborator

@mknorps mknorps left a comment

Choose a reason for hiding this comment

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

Great that you took out package-related functions to a separate module!
The rest of the refactor following that change is consistent and a good improvement.

What I worry here about is that Analysis object starts becoming too complicated.
There are a lot of conditional statements, asserts and following what is happening in the case of the default `--check option in the tool is not straightforward.

I still have the tests section to check so for now I will leave this comment and the one in the code :)

fawltydeps/main.py Show resolved Hide resolved
jherland added 7 commits March 8, 2023 12:27
These tests will be moved to a different module once we refactor code
out of the check module.

We also need to find some way to mock the LocalPackageLookup, so that we
can isolate these tests from the current Python environment.
The new functions calculate_undeclared() and calculate_unused() perform
the first and second half of what compare_imports_to_dependencies() used
to do.

For now they are simply called from compare_imports_to_dependencies(),
but this they will soon replace it altogether.
After having reduced compare_imports_to_dependencies() to a thin wrapper
for the tree underlying functions resolve_dependencies(),
calculate_undeclared(), and calculate_unused(), we can now easily make
the former obsolete by moving the three function calls into
Analysis.create().

Removing compare_imports_to_dependencies() will be done in a later
commit.
We will soon remove compare_imports_to_dependencies(), but we have a lot
of parametrized tests for this function that we want to retain.

Turn each test vector into a FDTestVector instance to make the
definition of each vector more readable, and then use the same test data
to test resolve_dependencies(), calculate_undeclared(), and
calculate_unused() in addition to compare_imports_to_dependencies().

Based on Maria's great idea in [1].

[1]: #193 (comment)
This moves:
 - DependenciesMapping and Package from fawltydeps.types
 - LocalPackageLookup and resolve_dependencies from fawltydeps.check
into the new fawltydeps.packages module.

On the tests/ side, we collect:
 - Package tests from test_types
 - LocalPackageLookup and resolve_dependencies() tests from
   test_map_dep_name_to_import_names
 - resolve_dependencies() tests from
   test_compare_imports_to_dependencies
into the corresponding new test_packages modules.

Since we reuse the FDTestVector test vectors from the
test_compare_imports_to_dependencies in test_packages, these now move
into the utils module, to be easily shared between test modules.

Finally, when combining resolve_dependencies() tests from
test_map_dep_name_to_import_names + test_compare_imports_to_dependencies
some overlap in test cases was identified and eliminated. The test
parameters to test_resolve_dependencies__focus_on_mappings() retain the
deduplicated test parameters.
@jherland jherland force-pushed the jherland/refactor-compare-code branch from 7b7b861 to 3914aea Compare March 8, 2023 11:28
Copy link
Collaborator

@mknorps mknorps left a comment

Choose a reason for hiding this comment

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

I have few comments regarding the test section, but it is really good and better read 🎉

This PR is ready to 🚀 just after addressing those small things.

fawltydeps/check.py Show resolved Hide resolved
tests/utils.py Show resolved Hide resolved
tests/utils.py Outdated Show resolved Hide resolved
tests/utils.py Show resolved Hide resolved
jherland and others added 2 commits March 9, 2023 16:15
Co-authored-by: Maria Knorps <maria.knorps@tweag.io>
This makes failing tests document their inputs, which is helpful when
debugging.
@jherland jherland force-pushed the jherland/refactor-compare-code branch from 25767ae to c9abe0a Compare March 9, 2023 15:21
@jherland jherland merged commit 3ce1bde into main Mar 9, 2023
@jherland jherland deleted the jherland/refactor-compare-code branch March 9, 2023 15:31
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