mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
improve(tests): add more test cases to increase coverage
This commit is contained in:
parent
50470f7836
commit
d5b182e445
@ -18,6 +18,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
self.modules = ['flask', 'requests', 'sqlalchemy', 'docopt', 'ujson', 'nonexistendmodule']
|
self.modules = ['flask', 'requests', 'sqlalchemy', 'docopt', 'ujson', 'nonexistendmodule']
|
||||||
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
||||||
self.requirements_path = os.path.join(self.project, "requirements.txt")
|
self.requirements_path = os.path.join(self.project, "requirements.txt")
|
||||||
|
self.alt_requirement_path = os.path.join(self.project, "requirements2.txt")
|
||||||
|
|
||||||
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)
|
||||||
@ -52,11 +53,31 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
for item in self.modules[:-1]:
|
for item in self.modules[:-1]:
|
||||||
self.assertTrue(item in data)
|
self.assertTrue(item in data)
|
||||||
|
|
||||||
|
def test_init_local_only(self):
|
||||||
|
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:
|
||||||
|
data = f.readlines()
|
||||||
|
self.assertEqual(len(data), 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})
|
||||||
|
assert os.path.exists(self.alt_requirement_path) == 1
|
||||||
|
with open(self.alt_requirement_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:
|
try:
|
||||||
os.remove(self.requirements_path)
|
os.remove(self.requirements_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
os.remove(self.alt_requirement_path)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user