-
Notifications
You must be signed in to change notification settings - Fork 399
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid_module |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
valid_package | ||
tests |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
import io | ||
import sys | ||
import unittest | ||
from unittest.mock import patch | ||
import sys | ||
import os | ||
import requests | ||
|
||
|
@@ -48,7 +50,14 @@ | |
os.path.dirname(__file__), "_data_duplicated_deps" | ||
) | ||
self.requirements_path = os.path.join(self.project, "requirements.txt") | ||
self.alt_requirement_path = os.path.join(self.project, "requirements2.txt") | ||
self.alt_requirement_path = os.path.join( | ||
self.project, | ||
"requirements2.txt" | ||
) | ||
self.local_packages_path = os.path.join( | ||
os.path.dirname(__file__), | ||
"_local_packages" | ||
) | ||
|
||
def test_get_all_imports(self): | ||
imports = pipreqs.get_all_imports(self.project) | ||
|
@@ -109,6 +118,15 @@ | |
for item in imports_with_info: | ||
self.assertTrue(item["name"].lower() in self.local) | ||
|
||
def test_get_locally_installed_packages(self): | ||
with patch.object(sys, 'path', new=[self.local_packages_path]): | ||
local_installed_packages = pipreqs.get_locally_installed_packages() | ||
expected_output = [ | ||
{'exports': ['valid_package'], 'name': 'valid_package', 'version': '1.0.0'}, | ||
{'exports': [], 'name': 'EGG', 'version': 'INFO'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
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 |
||
] | ||
self.assertEqual(local_installed_packages, expected_output) | ||
|
||
def test_init(self): | ||
""" | ||
Test that all modules we will test upon are in requirements file | ||
|
There was a problem hiding this comment.
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