mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Fix(tests): Increase test coverage
This commit is contained in:
parent
3f5831a1c4
commit
9fcb4216a2
@ -86,7 +86,7 @@ def init(args):
|
||||
generate_requirements_file(path, imports_with_info)
|
||||
print ("Successfuly saved requirements file in: " + path)
|
||||
|
||||
def main():
|
||||
def main(): # pragma: no cover
|
||||
args = docopt(__doc__, version='xstat 0.1')
|
||||
log_level = logging.WARNING
|
||||
if args['--debug']:
|
||||
@ -99,4 +99,4 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main() # pragma: no cover
|
@ -1,4 +0,0 @@
|
||||
flask==0.10.1
|
||||
requests==2.6.0
|
||||
sqlalchemy==1.0.0
|
||||
docopt==0.6.2
|
@ -9,9 +9,12 @@ import time
|
||||
import sys
|
||||
import signal
|
||||
import requests
|
||||
import nonexistendmodule
|
||||
# Ignore this Line
|
||||
import flask.ext.somext
|
||||
from sqlalchemy import model
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
@ -16,12 +16,13 @@ from pipreqs import pipreqs
|
||||
class TestPipreqs(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.modules = ['flask', 'requests', 'sqlalchemy', 'docopt']
|
||||
self.modules = ['flask', 'requests', 'sqlalchemy', 'docopt', 'nonexistendmodule']
|
||||
self.project = os.path.join(os.path.dirname(__file__),"_data")
|
||||
self.requirements_path = os.path.join(self.project,"requirements.txt")
|
||||
|
||||
def test_get_all_imports(self):
|
||||
path = os.path.join(os.path.dirname(__file__),"_data")
|
||||
imports = pipreqs.get_all_imports(path)
|
||||
self.assertEqual(len(imports),4, "Incorrect Imports array length")
|
||||
imports = pipreqs.get_all_imports(self.project)
|
||||
self.assertEqual(len(imports),5, "Incorrect Imports array length")
|
||||
for item in imports:
|
||||
self.assertTrue(item in self.modules, "Import is missing")
|
||||
self.assertFalse("time" in imports)
|
||||
@ -30,15 +31,26 @@ class TestPipreqs(unittest.TestCase):
|
||||
self.assertFalse("__future__" in imports)
|
||||
|
||||
def test_get_imports_info(self):
|
||||
path = os.path.join(os.path.dirname(__file__),"_data")
|
||||
imports = pipreqs.get_all_imports(path)
|
||||
imports = pipreqs.get_all_imports(self.project)
|
||||
with_info = pipreqs.get_imports_info(imports)
|
||||
# Should contain only 4 Elements without the "nonexistendmodule"
|
||||
self.assertEqual(len(with_info),4, "Length of imports array with info is wrong")
|
||||
for item in with_info:
|
||||
self.assertTrue(item['name'] in self.modules, "Import item appears to be missing")
|
||||
|
||||
def test_init(self):
|
||||
pipreqs.init({'<path>':self.project, '--savepath':None})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
data = f.read()
|
||||
for item in self.modules[:-1]:
|
||||
self.assertTrue(item in data)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
try:
|
||||
os.remove(self.requirements_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user