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

Add unit test for "get_locally_installed_packages" function #390

Closed

Conversation

willianrocha
Copy link
Contributor

validating ignore module and packages

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.25% 🎉

Comparison is base (f97d8b9) 86.71% compared to head (ce27276) 86.97%.
Report is 22 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #390      +/-   ##
==========================================
+ Coverage   86.71%   86.97%   +0.25%     
==========================================
  Files           2        2              
  Lines         256      261       +5     
==========================================
+ Hits          222      227       +5     
  Misses         34       34              
Files Changed Coverage Δ
pipreqs/__init__.py 100.00% <100.00%> (ø)
pipreqs/pipreqs.py 86.82% <100.00%> (+0.26%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tests/test_pipreqs.py Outdated Show resolved Hide resolved
expected_output = [
{'exports': [], 'name': 'invalid_package', 'version': None},
{'exports': ['valid_package'], 'name': 'valid_package', 'version': '1.0.0'},
{'exports': [], 'name': 'EGG', 'version': 'INFO'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry, I dont understand this test. Could you explain it to me? why this becomes the output and why is the module invalid? Is it because it haz an additional folder?

Copy link
Contributor

Choose a reason for hiding this comment

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

First of all, we based our tests on our understanding of the code. We don't know exactly how pip builds the structure of a package.

  1. The first test case was not necessary, so we decided to remove it.
  2. The second one was called as a "valid_package" because its "top_level.txt" file has one module named "valid_package" that is not in our code's blacklist (which is a variable called ignore with value ["tests", "_tests", "egg", "EGG", "info"]) and also has a module named "tests" that is in that blacklist.
  3. The last test case makes sure that "top_level.txt" files that are inside a folder that starts with "EGG" are not considered.

We tried to understand the code's behavior by reading "setuptools" documentation (link), but we did not understand much. It requires a lot of reading and time for understanding.

If you think it's okay for us to use our time to study this and then validate if it's right, that is okay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you elaborate a bit more as to why the first test was unnecessary?

We tried to understand the code's behavior by reading "setuptools" documentation (link), but we did not understand much. It requires a lot of reading and time for understanding.

If you think it's okay for us to use our time to study this and then validate if it's right, that is okay.

I see, I wasn´t expecting it to be that convoluted. I will get back to you as to what we should do, for now just fix the double import and focus on the other tasks

@alan-barzilay
Copy link
Collaborator

Also, you should push to next, not master

@alan-barzilay
Copy link
Collaborator

@willianrocha could you take a look at PR #384 also? It seems related to this test, I would like your opinion about the issue, are non top_level pip packages something compliant with how pip works and the documentation? if so it seems one of the test cases implemented in this test could be a problem

@willianrocha willianrocha changed the base branch from master to next October 4, 2023 20:40
@mateuslatrova
Copy link
Contributor

mateuslatrova commented Oct 4, 2023

@willianrocha could you take a look at PR #384 also? It seems related to this test, I would like your opinion about the issue, are non top_level pip packages something compliant with how pip works and the documentation? if so it seems one of the test cases implemented in this test could be a problem

@alan-barzilay
We looked into some packages that are installed in our environments.

Packages that are in the "EGG" format have the "top_level.txt" file, but others don't. For example, pandas is a package in "dist.info" format and it does not have the "top_level.txt" file, but it has the "METADATA" file mentioned in the PR you just said.

I don't know which one is compliant or not, but it seems to me that maybe our code is not getting all information it is looking for... In the case of pandas, for example, it would not get the package from the "top_level.txt" and would continue running...

Also, in the EGG format, the "PKG-INFO" file seems a lot like the "METADATA" file from "DIST-INFO" format.

Obs.: it looks like EGG packages are deprecated...

Maybe we could handle both types of distribution...

@@ -11,6 +11,8 @@
import io
import sys
import unittest
from unittest.mock import patch
import sys
Copy link
Collaborator

Choose a reason for hiding this comment

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

sys is already imported in line 12, 3 lines up haha

expected_output = [
{'exports': [], 'name': 'invalid_package', 'version': None},
{'exports': ['valid_package'], 'name': 'valid_package', 'version': '1.0.0'},
{'exports': [], 'name': 'EGG', 'version': 'INFO'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you elaborate a bit more as to why the first test was unnecessary?

We tried to understand the code's behavior by reading "setuptools" documentation (link), but we did not understand much. It requires a lot of reading and time for understanding.

If you think it's okay for us to use our time to study this and then validate if it's right, that is okay.

I see, I wasn´t expecting it to be that convoluted. I will get back to you as to what we should do, for now just fix the double import and focus on the other tasks

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.

4 participants