2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2020-08-08 07:16:06 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-07-28 13:20:12 -04:00
|
|
|
require "livecheck/strategy"
|
2020-08-08 07:16:06 +05:30
|
|
|
|
|
|
|
describe Homebrew::Livecheck::Strategy::Pypi do
|
|
|
|
subject(:pypi) { described_class }
|
|
|
|
|
2021-07-28 13:20:12 -04:00
|
|
|
let(:pypi_url) { "https://files.pythonhosted.org/packages/ab/cd/efg/example-1.2.3.tar.gz" }
|
2020-08-08 07:16:06 +05:30
|
|
|
let(:non_pypi_url) { "https://brew.sh/test" }
|
|
|
|
|
2021-07-28 13:20:12 -04:00
|
|
|
let(:generated) {
|
|
|
|
{
|
|
|
|
url: "https://pypi.org/project/example/#files",
|
|
|
|
regex: %r{href=.*?/packages.*?/example[._-]v?(\d+(?:\.\d+)*(?:[._-]post\d+)?)\.t}i,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 07:16:06 +05:30
|
|
|
describe "::match?" do
|
2021-08-10 17:39:11 -04:00
|
|
|
it "returns true for a PyPI URL" do
|
2020-08-08 07:16:06 +05:30
|
|
|
expect(pypi.match?(pypi_url)).to be true
|
|
|
|
end
|
|
|
|
|
2021-08-10 17:39:11 -04:00
|
|
|
it "returns false for a non-PyPI URL" do
|
2020-08-08 07:16:06 +05:30
|
|
|
expect(pypi.match?(non_pypi_url)).to be false
|
|
|
|
end
|
|
|
|
end
|
2021-07-28 13:20:12 -04:00
|
|
|
|
|
|
|
describe "::generate_input_values" do
|
|
|
|
it "returns a hash containing url and regex for an PyPI URL" do
|
|
|
|
expect(pypi.generate_input_values(pypi_url)).to eq(generated)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an empty hash for a non-PyPI URL" do
|
|
|
|
expect(pypi.generate_input_values(non_pypi_url)).to eq({})
|
|
|
|
end
|
|
|
|
end
|
2020-08-08 07:16:06 +05:30
|
|
|
end
|