From b0d90868f832e6af241e0adb91191a99f5d52847 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Tue, 13 Oct 2020 23:26:48 +0200 Subject: [PATCH] utils: fix canonical package name regex Relates-to: python-poetry/poetry#3132 Relates-to: python-poetry/poetry#3200 --- poetry/core/utils/helpers.py | 2 +- tests/utils/test_helpers.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/poetry/core/utils/helpers.py b/poetry/core/utils/helpers.py index b4bf7902f..920e14288 100644 --- a/poetry/core/utils/helpers.py +++ b/poetry/core/utils/helpers.py @@ -17,7 +17,7 @@ from collections import Mapping -_canonicalize_regex = re.compile("[-_]+") +_canonicalize_regex = re.compile(r"[-_.]+") def canonicalize_name(name): # type: (str) -> str diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index a2e423c1d..267e83296 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -1,3 +1,6 @@ +import pytest + +from poetry.core.utils.helpers import canonicalize_name from poetry.core.utils.helpers import parse_requires @@ -52,3 +55,10 @@ def test_parse_requires(): 'isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort ; extra == "dev"', ] assert result == expected + + +@pytest.mark.parametrize( + "raw", ["a-b-c", "a.b-c", "a.b.c", "a_b-c", "a_b_c", "a-b_c", "a.b_c", "a-b.c"] +) +def test_utils_helpers_canonical_names(raw): + assert canonicalize_name(raw) == "a-b-c"