|
4 | 4 | require "tmpdir" |
5 | 5 |
|
6 | 6 | describe Licensed::Sources::Pip do |
| 7 | + class TestablePipSource < Licensed::Sources::Pip |
| 8 | + public :parse_package_info, :homepage |
| 9 | + end |
| 10 | + |
| 11 | + let(:config) { Licensed::AppConfiguration.new({ "source_path" => Dir.pwd }) } |
| 12 | + let(:source) { TestablePipSource.new(config) } |
| 13 | + |
| 14 | + it "parses pip show continuation lines" do |
| 15 | + parsed = source.parse_package_info( |
| 16 | + <<~INFO |
| 17 | + Name: azure-core |
| 18 | + Project-URLs: |
| 19 | + Repository, https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core |
| 20 | + INFO |
| 21 | + ) |
| 22 | + |
| 23 | + assert_equal( |
| 24 | + "Repository, https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core", |
| 25 | + parsed["Project-URLs"] |
| 26 | + ) |
| 27 | + end |
| 28 | + |
| 29 | + it "falls back to Project-URLs when Home-page is empty" do |
| 30 | + homepage = source.homepage( |
| 31 | + { |
| 32 | + "Home-page" => "", |
| 33 | + "Project-URLs" => "Repository, https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core" |
| 34 | + } |
| 35 | + ) |
| 36 | + |
| 37 | + assert_equal "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core", homepage |
| 38 | + end |
| 39 | + |
| 40 | + it "prefers Home URL from Project-URLs even when listed last" do |
| 41 | + homepage = source.homepage( |
| 42 | + { |
| 43 | + "Home-page" => "", |
| 44 | + "Project-URLs" => [ |
| 45 | + "Documentation, https://learn.microsoft.com/azure/", |
| 46 | + "Repository, https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core", |
| 47 | + "Home, https://azure.microsoft.com/en-us/products/" |
| 48 | + ].join("\n") |
| 49 | + } |
| 50 | + ) |
| 51 | + |
| 52 | + assert_equal "https://azure.microsoft.com/en-us/products/", homepage |
| 53 | + end |
| 54 | + |
| 55 | + it "prefers Repository URL when Home is not present" do |
| 56 | + homepage = source.homepage( |
| 57 | + { |
| 58 | + "Home-page" => "", |
| 59 | + "Project-URLs" => [ |
| 60 | + "Documentation, https://learn.microsoft.com/azure/", |
| 61 | + "Repository, https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core", |
| 62 | + "Source, https://example.com/source" |
| 63 | + ].join("\n") |
| 64 | + } |
| 65 | + ) |
| 66 | + |
| 67 | + assert_equal "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core", homepage |
| 68 | + end |
| 69 | + |
| 70 | + it "filters malformed and non-http Project-URLs entries" do |
| 71 | + homepage = source.homepage( |
| 72 | + { |
| 73 | + "Home-page" => "", |
| 74 | + "Project-URLs" => [ |
| 75 | + "NoCommaEntry", |
| 76 | + "Documentation, ftp://learn.microsoft.com/azure/", |
| 77 | + "Documentation, https://learn.microsoft.com/azure/", |
| 78 | + "Source, not-a-url" |
| 79 | + ].join("\n") |
| 80 | + } |
| 81 | + ) |
| 82 | + |
| 83 | + assert_equal "https://learn.microsoft.com/azure/", homepage |
| 84 | + end |
| 85 | + |
| 86 | + it "prefers Home-page when present" do |
| 87 | + homepage = source.homepage( |
| 88 | + { |
| 89 | + "Home-page" => "https://example.com/home", |
| 90 | + "Project-URLs" => "Repository, https://github.com/example/repo" |
| 91 | + } |
| 92 | + ) |
| 93 | + |
| 94 | + assert_equal "https://example.com/home", homepage |
| 95 | + end |
| 96 | + |
| 97 | + it "returns empty Home-page when Project-URLs is a non-string value" do |
| 98 | + package = Hash.new(0) |
| 99 | + package["Home-page"] = "" |
| 100 | + |
| 101 | + assert_equal "", source.homepage(package) |
| 102 | + end |
| 103 | + |
7 | 104 | it "finds lowercase dist-info directories for mixed-case package names" do |
8 | 105 | Dir.mktmpdir do |dir| |
9 | 106 | dist_info = File.join(dir, "pyjwt-2.12.0.dist-info") |
|
0 commit comments