diff --git a/tests/_data_duplicated_deps/db.py b/tests/_data_duplicated_deps/db.py new file mode 100644 index 0000000..5e2a360 --- /dev/null +++ b/tests/_data_duplicated_deps/db.py @@ -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'. diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index 99fe8fc..b8992d4 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -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.