mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 03:55:22 +00:00
Added tests for get_import_name_without_alias
This commit is contained in:
parent
b30777fb41
commit
907e649e69
@ -97,10 +97,10 @@ def get_locally_installed_packages():
|
|||||||
package_import = f.read().strip().split("\n")
|
package_import = f.read().strip().split("\n")
|
||||||
for item in package_import:
|
for item in package_import:
|
||||||
if item not in ["tests", "_tests"]:
|
if item not in ["tests", "_tests"]:
|
||||||
packages[item] = {
|
packages[item] = {
|
||||||
'version': package[1].replace(".dist", ""),
|
'version': package[1].replace(".dist", ""),
|
||||||
'name': package[0]
|
'name': package[0]
|
||||||
}
|
}
|
||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|
||||||
@ -113,17 +113,17 @@ def get_import_local(imports):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_pkg_names_from_import_names(pkgs):
|
def get_pkg_names_from_import_names(pkgs):
|
||||||
result = []
|
result = []
|
||||||
with open(os.path.join(os.path.dirname(__file__), "mapping"), "r") as f:
|
with open(os.path.join(os.path.dirname(__file__), "mapping"), "r") as f:
|
||||||
data = [x.strip().split(":") for x in f.readlines()]
|
data = [x.strip().split(":") for x in f.readlines()]
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
toappend = pkg
|
toappend = pkg
|
||||||
for item in data:
|
for item in data:
|
||||||
if item[0] == pkg:
|
if item[0] == pkg:
|
||||||
toappend = item[1]
|
toappend = item[1]
|
||||||
break
|
break
|
||||||
result.append(toappend)
|
result.append(toappend)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_import_name_without_alias(import_name):
|
def get_import_name_without_alias(import_name):
|
||||||
return import_name.partition(' as ')[0].partition('.')[0].strip()
|
return import_name.partition(' as ')[0].partition('.')[0].strip()
|
||||||
|
@ -68,6 +68,11 @@ 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_get_import_name_without_alias(self):
|
||||||
|
import_name_with_alias = "requests as R"
|
||||||
|
expected_import_name_without_alias = "requests"
|
||||||
|
import_name_without_aliases = pipreqs.get_import_name_without_alias(import_name_with_alias)
|
||||||
|
self.assertEqual(import_name_without_aliases, expected_import_name_without_alias, "The import alias was not correctly stripped")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user