Add test for duplicated dependencies

This commit is contained in:
Dmitry Pribysh 2016-02-10 20:49:13 +03:00
parent 36efe7e219
commit c3761598ce
2 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1,6 @@
import pymongo
from bson.objectid import ObjectId
# 'bson' package is mapped to 'pymongo'.
# But running pipreqs should not result in two duplicated
# lines 'pymongo==x.x.x'.

View File

@ -26,6 +26,7 @@ class TestPipreqs(unittest.TestCase):
self.project = os.path.join(os.path.dirname(__file__), "_data")
self.project_invalid = os.path.join(os.path.dirname(__file__), "_invalid_data")
self.project_with_ignore_directory = os.path.join(os.path.dirname(__file__), "_data_ignore")
self.project_with_duplicated_deps = os.path.join(os.path.dirname(__file__), "_data_duplicated_deps")
self.requirements_path = os.path.join(self.project, "requirements.txt")
self.alt_requirement_path = os.path.join(
self.project, "requirements2.txt")
@ -43,6 +44,12 @@ class TestPipreqs(unittest.TestCase):
self.assertFalse("django" in imports)
self.assertFalse("models" in imports)
def test_deduplicate_dependencies(self):
imports = pipreqs.get_all_imports(self.project_with_duplicated_deps)
pkgs = pipreqs.get_pkg_names(imports)
self.assertEqual(len(pkgs), 1)
self.assertIn("pymongo", pkgs)
def test_invalid_python(self):
"""
Test that invalid python files cannot be imported.