mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +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)
|
generate_requirements_file(path, imports_with_info)
|
||||||
print ("Successfuly saved requirements file in: " + path)
|
print ("Successfuly saved requirements file in: " + path)
|
||||||
|
|
||||||
def main():
|
def main(): # pragma: no cover
|
||||||
args = docopt(__doc__, version='xstat 0.1')
|
args = docopt(__doc__, version='xstat 0.1')
|
||||||
log_level = logging.WARNING
|
log_level = logging.WARNING
|
||||||
if args['--debug']:
|
if args['--debug']:
|
||||||
@ -99,4 +99,4 @@ def main():
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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 sys
|
||||||
import signal
|
import signal
|
||||||
import requests
|
import requests
|
||||||
|
import nonexistendmodule
|
||||||
|
# Ignore this Line
|
||||||
import flask.ext.somext
|
import flask.ext.somext
|
||||||
from sqlalchemy import model
|
from sqlalchemy import model
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pass
|
pass
|
||||||
|
@ -16,12 +16,13 @@ from pipreqs import pipreqs
|
|||||||
class TestPipreqs(unittest.TestCase):
|
class TestPipreqs(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
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):
|
def test_get_all_imports(self):
|
||||||
path = os.path.join(os.path.dirname(__file__),"_data")
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
imports = pipreqs.get_all_imports(path)
|
self.assertEqual(len(imports),5, "Incorrect Imports array length")
|
||||||
self.assertEqual(len(imports),4, "Incorrect Imports array length")
|
|
||||||
for item in imports:
|
for item in imports:
|
||||||
self.assertTrue(item in self.modules, "Import is missing")
|
self.assertTrue(item in self.modules, "Import is missing")
|
||||||
self.assertFalse("time" in imports)
|
self.assertFalse("time" in imports)
|
||||||
@ -30,14 +31,25 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
self.assertFalse("__future__" in imports)
|
self.assertFalse("__future__" in imports)
|
||||||
|
|
||||||
def test_get_imports_info(self):
|
def test_get_imports_info(self):
|
||||||
path = os.path.join(os.path.dirname(__file__),"_data")
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
imports = pipreqs.get_all_imports(path)
|
|
||||||
with_info = pipreqs.get_imports_info(imports)
|
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")
|
self.assertEqual(len(with_info),4, "Length of imports array with info is wrong")
|
||||||
for item in with_info:
|
for item in with_info:
|
||||||
self.assertTrue(item['name'] in self.modules, "Import item appears to be missing")
|
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):
|
def tearDown(self):
|
||||||
|
try:
|
||||||
|
os.remove(self.requirements_path)
|
||||||
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user