mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Adding only venv use case test
This commit is contained in:
parent
7c946be04a
commit
68dd38a4c8
@ -50,6 +50,7 @@ from docopt import docopt
|
||||
import requests
|
||||
from yarg import json2package
|
||||
from yarg.exceptions import HTTPError
|
||||
from typing import Optional
|
||||
|
||||
from pipreqs import __version__
|
||||
|
||||
@ -318,9 +319,8 @@ def get_locally_installed_packages(use_venv_packages: bool, encoding="utf-8"):
|
||||
return packages
|
||||
|
||||
|
||||
def get_import_local(imports, use_venv_packages: bool, encoding="utf-8"):
|
||||
def get_import_local(imports, use_venv_packages: Optional[bool]=False, encoding="utf-8"):
|
||||
local = get_locally_installed_packages(use_venv_packages=use_venv_packages)
|
||||
print('LOCAL: ', local)
|
||||
result = []
|
||||
for item in imports:
|
||||
# search through local packages
|
||||
@ -331,7 +331,6 @@ def get_import_local(imports, use_venv_packages: bool, encoding="utf-8"):
|
||||
if item in package["exports"] or item == package["name"]:
|
||||
result.append(package)
|
||||
|
||||
print(result)
|
||||
# removing duplicates of package/version
|
||||
# had to use second method instead of the previous one,
|
||||
# because we have a list in the 'exports' field
|
||||
|
12
tests/_data_ignore/requirements.txt
Normal file
12
tests/_data_ignore/requirements.txt
Normal file
@ -0,0 +1,12 @@
|
||||
asposestorage==1.0.2
|
||||
beautifulsoup4==4.13.3
|
||||
boto==2.49.0
|
||||
docopt==0.6.2
|
||||
Flask==3.1.0
|
||||
ipython==8.12.3
|
||||
nose==1.3.7
|
||||
peewee==3.17.9
|
||||
pyflakes==3.1.0
|
||||
Requests==2.32.3
|
||||
SQLAlchemy==2.0.40
|
||||
ujson==5.10.0
|
1
tests/_data_notebook/requirements.txt
Normal file
1
tests/_data_notebook/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
|
@ -156,6 +156,22 @@ class TestPipreqs(unittest.TestCase):
|
||||
for item in imports_with_info:
|
||||
self.assertTrue(item["name"].lower() in self.local)
|
||||
|
||||
@patch("pipreqs.pipreqs.get_locally_installed_packages")
|
||||
def test_get_import_local_only_from_venv(self, mock_get_local_packages):
|
||||
mock_get_local_packages.return_value = [
|
||||
{"name": "requests", "version": "2.31.0", "exports": ["requests"]},
|
||||
{"name": "docopt", "version": "0.6.2", "exports": ["docopt"]},
|
||||
]
|
||||
|
||||
imports = {"requests": "2.31.0", "docopt": "0.6.2", "flask": "3.0.2"}
|
||||
|
||||
result = pipreqs.get_import_local(imports, use_venv_packages=True)
|
||||
|
||||
self.assertEqual(result, [
|
||||
{"name": "requests", "version": "2.31.0", "exports": ["requests"]},
|
||||
{"name": "docopt", "version": "0.6.2", "exports": ["docopt"]},
|
||||
])
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test that all modules we will test upon are in requirements file
|
||||
@ -194,6 +210,7 @@ class TestPipreqs(unittest.TestCase):
|
||||
"--savepath": None,
|
||||
"--print": False,
|
||||
"--use-local": True,
|
||||
"--only-venv": False,
|
||||
"--force": True,
|
||||
"--proxy": None,
|
||||
"--pypi-server": None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user