From 84f1abafd3a707b464f039892ef48b9e282d0d4a Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 24 Oct 2018 09:52:56 +0800 Subject: Call os.path.normpath to normalize paths for comp --- pkg_resources/tests/test_pkg_resources.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg_resources/tests') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 62a39b8f..81b67a31 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -236,3 +236,8 @@ class TestDeepVersionLookupDistutils: req = pkg_resources.Requirement.parse('foo>=1.9') dist = pkg_resources.WorkingSet([env.paths['lib']]).find(req) assert dist.version == version + + def test_normalize_path(self, tmpdir): + path = str(tmpdir) + expected = os.path.normcase(os.path.normpath(os.path.realpath(path))) + assert pkg_resources.normalize_path(path) == expected -- cgit v1.2.1 From 90325195b5bf35afa12b699a7e9fddc0571e1551 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 26 Oct 2018 10:13:15 +0800 Subject: Test normalize_path on various inputs --- pkg_resources/tests/test_pkg_resources.py | 56 ++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'pkg_resources/tests') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 81b67a31..416f9aff 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -237,7 +237,55 @@ class TestDeepVersionLookupDistutils: dist = pkg_resources.WorkingSet([env.paths['lib']]).find(req) assert dist.version == version - def test_normalize_path(self, tmpdir): - path = str(tmpdir) - expected = os.path.normcase(os.path.normpath(os.path.realpath(path))) - assert pkg_resources.normalize_path(path) == expected + @pytest.mark.parametrize( + 'unnormalized, normalized', + [ + ('foo', 'foo'), + ('foo/', 'foo'), + ('foo/bar', 'foo/bar'), + ('foo/bar/', 'foo/bar'), + ], + ) + def test_normalize_path_trailing_sep(self, unnormalized, normalized): + """Ensure the trailing slash is cleaned for path comparison. + + See pypa/setuptools#1519. + """ + result_from_unnormalized = pkg_resources.normalize_path(unnormalized) + result_from_normalized = pkg_resources.normalize_path(normalized) + assert result_from_unnormalized == result_from_normalized + + @pytest.mark.skipif( + os.path.normcase('A') != os.path.normcase('a'), + reason='Testing case-insensitive filesystems.', + ) + @pytest.mark.parametrize( + 'unnormalized, normalized', + [ + ('MiXeD/CasE', 'mixed/case'), + ], + ) + def test_normalize_path_normcase(self, unnormalized, normalized): + """Ensure mixed case is normalized on case-insensitive filesystems. + """ + result_from_unnormalized = pkg_resources.normalize_path(unnormalized) + result_from_normalized = pkg_resources.normalize_path(normalized) + assert result_from_unnormalized == result_from_normalized + + @pytest.mark.skipif( + os.path.sep != '\\', + reason='Testing systems using backslashes as path separators.', + ) + @pytest.mark.parametrize( + 'unnormalized, expected', + [ + ('forward/slash', 'forward\\slash'), + ('forward/slash/', 'forward\\slash'), + ('backward\\slash\\', 'backward\\slash'), + ], + ) + def test_normalize_path_backslash_sep(self, unnormalized, expected): + """Ensure path seps are cleaned on backslash path sep systems. + """ + result = pkg_resources.normalize_path(unnormalized) + assert result.endswith(expected) -- cgit v1.2.1