Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 19 additions & 63 deletions Library/Homebrew/test/utils/pypi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
require "utils/pypi"

describe PyPI do
let(:pypi_package_url) do
let(:package_url) do
"https://files.pythonhosted.org/packages/b0/3f/2e1dad67eb172b6443b5eb37eb885a054a55cfd733393071499514140282/" \
"snakemake-5.29.0.tar.gz"
end
let(:old_pypi_package_url) do
let(:old_package_url) do
"https://files.pythonhosted.org/packages/6f/c4/da52bfdd6168ea46a0fe2b7c983b6c34c377a8733ec177cc00b197a96a9f/" \
"snakemake-5.28.0.tar.gz"
end
let(:non_pypi_package_url) do
"https://github.com/pypa/pip-audit/releases/download/v2.5.6/v2.5.6.tar.gz"
end

describe PyPI::Package do
let(:package_checksum) { "47417307d08ecb0707b3b29effc933bd63d8c8e3ab15509c62b685b7614c6568" }
Expand All @@ -25,8 +22,7 @@
let(:package_with_extra) { described_class.new("snakemake[foo]") }
let(:package_with_extra_and_version) { described_class.new("snakemake[foo]==5.28.0") }
let(:package_with_different_capitalization) { described_class.new("SNAKEMAKE") }
let(:package_from_pypi_url) { described_class.new(pypi_package_url, is_url: true) }
let(:package_from_non_pypi_url) { described_class.new(non_pypi_package_url, is_url: true) }
let(:package_from_url) { described_class.new(package_url, is_url: true) }
let(:other_package) { described_class.new("virtualenv==20.2.0") }

describe "initialize" do
Expand Down Expand Up @@ -70,50 +66,12 @@
expect(described_class.new("foo[bar,baz]==1.2.3").version).to eq "1.2.3"
end

it "initializes name from PyPI url" do
expect(described_class.new(pypi_package_url, is_url: true).name).to eq "snakemake"
end

it "initializes version from PyPI url" do
expect(described_class.new(pypi_package_url, is_url: true).version).to eq "5.29.0"
end
end

describe ".version=" do
it "sets for package names" do
package = described_class.new("snakemake==5.28.0")
expect(package.version).to eq "5.28.0"

package.version = "5.29.0"
expect(package.version).to eq "5.29.0"
end

it "sets for PyPI package URLs" do
package = described_class.new(old_pypi_package_url, is_url: true)
expect(package.version).to eq "5.28.0"

package.version = "5.29.0"
expect(package.version).to eq "5.29.0"
end

it "fails for non-PYPI package URLs" do
package = described_class.new(non_pypi_package_url, is_url: true)

expect { package.version = "1.2.3" }.to raise_error(ArgumentError)
end
end

describe ".valid_pypi_package?" do
it "is true for package names" do
expect(package.valid_pypi_package?).to be true
end

it "is true for PyPI URLs" do
expect(package_from_pypi_url.valid_pypi_package?).to be true
it "initializes name from url" do
expect(described_class.new(package_url, is_url: true).name).to eq "snakemake"
end

it "is false for non-PyPI URLs" do
expect(package_from_non_pypi_url.valid_pypi_package?).to be false
it "initializes version from url" do
expect(described_class.new(package_url, is_url: true).version).to eq "5.29.0"
end
end

Expand All @@ -123,36 +81,34 @@
end

it "gets pypi info from a package name and specified version" do
expect(package.pypi_info(new_version: "5.29.0")).to eq ["snakemake", pypi_package_url, package_checksum,
"5.29.0"]
expect(package.pypi_info(version: "5.29.0")).to eq ["snakemake", package_url, package_checksum, "5.29.0"]
end

it "gets pypi info from a package name with extra" do
expect(package_with_extra.pypi_info.first).to eq "snakemake"
end

it "gets pypi info from a package name and version" do
expect(package_with_version.pypi_info).to eq ["snakemake", old_pypi_package_url, old_package_checksum,
"5.28.0"]
expect(package_with_version.pypi_info).to eq ["snakemake", old_package_url, old_package_checksum, "5.28.0"]
end

it "gets pypi info from a package name with overridden version" do
expected_result = ["snakemake", pypi_package_url, package_checksum, "5.29.0"]
expect(package_with_version.pypi_info(new_version: "5.29.0")).to eq expected_result
expected_result = ["snakemake", package_url, package_checksum, "5.29.0"]
expect(package_with_version.pypi_info(version: "5.29.0")).to eq expected_result
end

it "gets pypi info from a package name, extras, and version" do
expected_result = ["snakemake", old_pypi_package_url, old_package_checksum, "5.28.0"]
expected_result = ["snakemake", old_package_url, old_package_checksum, "5.28.0"]
expect(package_with_extra_and_version.pypi_info).to eq expected_result
end

it "gets pypi info from a url" do
expect(package_from_pypi_url.pypi_info).to eq ["snakemake", pypi_package_url, package_checksum, "5.29.0"]
expect(package_from_url.pypi_info).to eq ["snakemake", package_url, package_checksum, "5.29.0"]
end

it "gets pypi info from a url with overridden version" do
expected_result = ["snakemake", old_pypi_package_url, old_package_checksum, "5.28.0"]
expect(package_from_pypi_url.pypi_info(new_version: "5.28.0")).to eq expected_result
expected_result = ["snakemake", old_package_url, old_package_checksum, "5.28.0"]
expect(package_from_url.pypi_info(version: "5.28.0")).to eq expected_result
end
end

Expand All @@ -174,7 +130,7 @@
end

it "returns string representation of package from url" do
expect(package_from_pypi_url.to_s).to eq "snakemake==5.29.0"
expect(package_from_url.to_s).to eq "snakemake==5.29.0"
end
end

Expand Down Expand Up @@ -213,15 +169,15 @@

describe "update_pypi_url", :needs_network do
it "updates url to new version" do
expect(described_class.update_pypi_url(old_pypi_package_url, "5.29.0")).to eq pypi_package_url
expect(described_class.update_pypi_url(old_package_url, "5.29.0")).to eq package_url
end

it "returns nil for invalid versions" do
expect(described_class.update_pypi_url(old_pypi_package_url, "0.0.0")).to be_nil
expect(described_class.update_pypi_url(old_package_url, "0.0.0")).to be_nil
end

it "returns nil for non-pypi urls" do
expect(described_class.update_pypi_url(non_pypi_package_url, "1.1")).to be_nil
expect(described_class.update_pypi_url("https://brew.sh/foo-1.0.tgz", "1.1")).to be_nil
end
end
end
Loading