Skip to content

Commit 3717581

Browse files
authored
Merge pull request #110 from abompard/strip-order
Strip return carriages before running `.endswith()`
2 parents cce5376 + d48eaa0 commit 3717581

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

liccheck/command_line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ def get_packages_info(requirement_file, no_deps=False):
147147

148148
def transform(dist):
149149
licenses = get_licenses_from_classifiers(dist) or get_license(dist) or []
150-
# Strip the useless "License" suffix and uniquify
151-
licenses = list(set([strip_license(l) for l in licenses]))
152150
# Removing Trailing windows generated \r
153151
licenses = list(set([strip_license_for_windows(l) for l in licenses]))
152+
# Strip the useless "License" suffix and uniquify
153+
licenses = list(set([strip_license(l) for l in licenses]))
154154

155155
return {
156156
"name": dist.project_name,

tests/test_get_packages_info.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22

3+
import pkg_resources
34
import pytest
45

56
from liccheck.command_line import get_packages_info
@@ -12,6 +13,24 @@ def test_license_strip(tmpfile):
1213
assert get_packages_info(tmppath)[0]["licenses"] == ["MIT"]
1314

1415

16+
def test_license_strip_with_return_carriage(tmp_path, mocker):
17+
resolve = mocker.patch("liccheck.command_line.resolve")
18+
req_path = tmp_path.joinpath("requirements.txt").as_posix()
19+
with open(req_path, "w") as tmpfh:
20+
tmpfh.write("pip\n")
21+
pkg_info_path = tmp_path.joinpath("PKG-INFO").as_posix()
22+
with open(pkg_info_path, "wb") as tmpfh:
23+
tmpfh.write(b"Metadata-Version: 2.1\r\n")
24+
tmpfh.write(b"Name: pip\r\n")
25+
tmpfh.write(b"Version: 23.3.1\r\n")
26+
tmpfh.write(b"Classifier: License :: OSI Approved :: MIT License\r\n")
27+
metadata = pkg_resources.PathMetadata(tmp_path, tmp_path)
28+
resolve.return_value = [
29+
pkg_resources.Distribution(project_name="pip", metadata=metadata)
30+
]
31+
assert get_packages_info(req_path)[0]["licenses"] == ["MIT"]
32+
33+
1534
def test_requirements_markers(tmpfile):
1635
tmpfh, tmppath = tmpfile
1736
tmpfh.write(

0 commit comments

Comments
 (0)