mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
style: PEP8 cleanup
This commit is contained in:
parent
b4ada100e7
commit
d4e1e9144d
@ -100,10 +100,10 @@ def get_locally_installed_packages():
|
||||
package_import = f.read().strip().split("\n")
|
||||
for item in package_import:
|
||||
if item not in ["tests", "_tests"]:
|
||||
packages[item] = {
|
||||
'version': package[1].replace(".dist", ""),
|
||||
'name': package[0]
|
||||
}
|
||||
packages[item] = {
|
||||
'version': package[1].replace(".dist", ""),
|
||||
'name': package[0]
|
||||
}
|
||||
return packages
|
||||
|
||||
|
||||
@ -115,18 +115,19 @@ def get_import_local(imports):
|
||||
result.append(local[item.lower()])
|
||||
return result
|
||||
|
||||
|
||||
def get_pkg_names_from_import_names(pkgs):
|
||||
result = []
|
||||
with open(os.path.join(os.path.dirname(__file__), "mapping"), "r") as f:
|
||||
data = [x.strip().split(":") for x in f.readlines()]
|
||||
for pkg in pkgs:
|
||||
toappend = pkg
|
||||
for item in data:
|
||||
if item[0] == pkg:
|
||||
toappend = item[1]
|
||||
break
|
||||
result.append(toappend)
|
||||
return result
|
||||
result = []
|
||||
with open(os.path.join(os.path.dirname(__file__), "mapping"), "r") as f:
|
||||
data = [x.strip().split(":") for x in f.readlines()]
|
||||
for pkg in pkgs:
|
||||
toappend = pkg
|
||||
for item in data:
|
||||
if item[0] == pkg:
|
||||
toappend = item[1]
|
||||
break
|
||||
result.append(toappend)
|
||||
return result
|
||||
|
||||
|
||||
def init(args):
|
||||
|
@ -8,24 +8,29 @@ test_pipreqs
|
||||
Tests for `pipreqs` module.
|
||||
"""
|
||||
|
||||
import unittest, os
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from pipreqs import pipreqs
|
||||
|
||||
|
||||
class TestPipreqs(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.modules = ['flask', 'requests', 'sqlalchemy', 'docopt', 'ujson', 'nonexistendmodule', 'bs4']
|
||||
self.modules = ['flask', 'requests', 'sqlalchemy',
|
||||
'docopt', 'ujson', 'nonexistendmodule', 'bs4']
|
||||
self.modules2 = ['beautifulsoup4']
|
||||
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
||||
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")
|
||||
|
||||
def test_get_all_imports(self):
|
||||
imports = pipreqs.get_all_imports(self.project)
|
||||
self.assertEqual(len(imports), 7, "Incorrect Imports array length")
|
||||
for item in imports:
|
||||
self.assertTrue(item.lower() in self.modules, "Import is missing: " + item)
|
||||
self.assertTrue(
|
||||
item.lower() in self.modules, "Import is missing: " + item)
|
||||
self.assertFalse("time" in imports)
|
||||
self.assertFalse("logging" in imports)
|
||||
self.assertFalse("curses" in imports)
|
||||
@ -38,17 +43,20 @@ class TestPipreqs(unittest.TestCase):
|
||||
with_info = pipreqs.get_imports_info(imports)
|
||||
# Should contain only 5 Elements without the "nonexistendmodule"
|
||||
print (with_info)
|
||||
self.assertEqual(len(with_info), 5, "Length of imports array with info is wrong")
|
||||
self.assertEqual(
|
||||
len(with_info), 5, "Length of imports array with info is wrong")
|
||||
for item in with_info:
|
||||
self.assertTrue(item['name'].lower() in self.modules, "Import item appears to be missing " + item['name'])
|
||||
|
||||
self.assertTrue(item['name'].lower(
|
||||
) in self.modules, "Import item appears to be missing " + item['name'])
|
||||
|
||||
def test_get_use_local_only(self):
|
||||
# should find only docopt and requests
|
||||
imports_with_info = pipreqs.get_import_local(self.modules)
|
||||
self.assertEqual(len(imports_with_info), 2)
|
||||
# should find only docopt and requests
|
||||
imports_with_info = pipreqs.get_import_local(self.modules)
|
||||
self.assertEqual(len(imports_with_info), 2)
|
||||
|
||||
def test_init(self):
|
||||
pipreqs.init({'<path>': self.project, '--savepath': None,'--use-local':None})
|
||||
pipreqs.init(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': None})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
data = f.read().lower()
|
||||
@ -56,21 +64,23 @@ class TestPipreqs(unittest.TestCase):
|
||||
self.assertTrue(item.lower() in data)
|
||||
|
||||
def test_init_local_only(self):
|
||||
pipreqs.init({'<path>': self.project, '--savepath': None,'--use-local':True})
|
||||
pipreqs.init(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': True})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
self.assertEqual(len(f.readlines()), 2, 'Only two local packages should be found')
|
||||
self.assertEqual(
|
||||
len(f.readlines()), 2, 'Only two local packages should be found')
|
||||
|
||||
def test_init_savepath(self):
|
||||
pipreqs.init({'<path>': self.project, '--savepath': self.alt_requirement_path,'--use-local':None})
|
||||
pipreqs.init({'<path>': self.project, '--savepath':
|
||||
self.alt_requirement_path, '--use-local': None})
|
||||
assert os.path.exists(self.alt_requirement_path) == 1
|
||||
with open(self.alt_requirement_path, "r") as f:
|
||||
data = f.read().lower()
|
||||
for item in self.modules[:-2]:
|
||||
self.assertTrue(item.lower() in data)
|
||||
for item in self.modules2:
|
||||
self.assertTrue(item.lower() in data)
|
||||
|
||||
self.assertTrue(item.lower() in data)
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user