mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Working on issue #88
This commit is contained in:
parent
6ca1f42d4e
commit
2022f25ae9
@ -368,6 +368,11 @@ def diff(file_, imports):
|
|||||||
def clean(file_, imports):
|
def clean(file_, imports):
|
||||||
"""Remove modules that aren't imported in project from file."""
|
"""Remove modules that aren't imported in project from file."""
|
||||||
modules_not_imported = compare_modules(file_, imports)
|
modules_not_imported = compare_modules(file_, imports)
|
||||||
|
|
||||||
|
if len(modules_not_imported) == 0:
|
||||||
|
logging.info("Nothing to clean in " + file_)
|
||||||
|
return
|
||||||
|
|
||||||
re_remove = re.compile("|".join(modules_not_imported))
|
re_remove = re.compile("|".join(modules_not_imported))
|
||||||
to_write = []
|
to_write = []
|
||||||
|
|
||||||
|
@ -31,6 +31,10 @@ from pyflakes.test.test_imports import Test as TestImports
|
|||||||
# Nose
|
# Nose
|
||||||
from nose.importer import Importer, add_path, remove_path # loader.py
|
from nose.importer import Importer, add_path, remove_path # loader.py
|
||||||
|
|
||||||
|
# see issue #88
|
||||||
|
import analytics
|
||||||
|
import flask_seasurf
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
@ -19,7 +19,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.modules = ['flask', 'requests', 'sqlalchemy',
|
self.modules = ['flask', 'requests', 'sqlalchemy',
|
||||||
'docopt', 'boto', 'ipython', 'pyflakes', 'nose',
|
'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics_python', 'flask_seasurf',
|
||||||
'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ]
|
'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ]
|
||||||
self.modules2 = ['beautifulsoup4']
|
self.modules2 = ['beautifulsoup4']
|
||||||
self.local = ["docopt", "requests", "nose", 'pyflakes']
|
self.local = ["docopt", "requests", "nose", 'pyflakes']
|
||||||
@ -33,7 +33,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_all_imports(self):
|
def test_get_all_imports(self):
|
||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
self.assertEqual(len(imports), 13)
|
self.assertEqual(len(imports), 15) # old value, 13
|
||||||
for item in imports:
|
for item in imports:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
item.lower() in self.modules, "Import is missing: " + item)
|
item.lower() in self.modules, "Import is missing: " + item)
|
||||||
@ -63,7 +63,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
with_info = pipreqs.get_imports_info(imports)
|
with_info = pipreqs.get_imports_info(imports)
|
||||||
# Should contain 10 items without the "nonexistendmodule" and "after_method_is_valid_even_if_not_pep8"
|
# Should contain 10 items without the "nonexistendmodule" and "after_method_is_valid_even_if_not_pep8"
|
||||||
self.assertEqual(len(with_info), 11)
|
self.assertEqual(len(with_info), 13) # old value, 11
|
||||||
for item in with_info:
|
for item in with_info:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
item['name'].lower() in self.modules,
|
item['name'].lower() in self.modules,
|
||||||
@ -200,6 +200,30 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
for item in ['beautifulsoup4==4.8.1', 'boto==2.49.0']:
|
for item in ['beautifulsoup4==4.8.1', 'boto==2.49.0']:
|
||||||
self.assertFalse(item.lower() in data)
|
self.assertFalse(item.lower() in data)
|
||||||
|
|
||||||
|
def test_clean(self):
|
||||||
|
"""
|
||||||
|
Test --clean parameter
|
||||||
|
"""
|
||||||
|
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
||||||
|
'--use-local': None, '--force': True, '--proxy': None,
|
||||||
|
'--pypi-server': None, '--diff': None, '--clean': None})
|
||||||
|
assert os.path.exists(self.requirements_path) == 1
|
||||||
|
# with open(self.requirements_path, "r") as f:
|
||||||
|
# print('A')
|
||||||
|
# for l in f: print(l)
|
||||||
|
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
||||||
|
'--use-local': None, '--force': None, '--proxy': None,
|
||||||
|
'--pypi-server': None, '--diff': None,
|
||||||
|
'--clean': self.requirements_path, '--no-pin': True})
|
||||||
|
# with open(self.requirements_path, "r") as f:
|
||||||
|
# print('B')
|
||||||
|
# for l in f: print(l)
|
||||||
|
with open(self.requirements_path, "r") as f:
|
||||||
|
data = f.read().lower()
|
||||||
|
print(data)
|
||||||
|
for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']:
|
||||||
|
self.assertTrue(item.lower() in data)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""
|
"""
|
||||||
Remove requiremnts.txt files that were written
|
Remove requiremnts.txt files that were written
|
||||||
|
Loading…
x
Reference in New Issue
Block a user