Sam Ford 78c7ad747a
Pypi: Update strategy regex
livecheck is returning an `Unable to get versions` error for the
`ansible-lint`, `aws-sam-cli`, and `pyqt-builder` formulae. These use
the `Pypi` strategy without a `livecheck` block, so they use the
generated regex from the strategy. The `Pypi` strategy matches the
version from the tarball link on the pypi.org package page but this
fails for these packages because the formula's `stable` tarball uses
hyphens in the filename (e.g., `ansible-lint-...`) but the current
tarball filename uses underscores (e.g., `ansible_lint-...`).

This addresses the issue by updating the strategy regex to replace
[escaped] `-` or `_` characters in the package name with `[_-]`, so
the regex will match regardless of the delimiter used in the formula
filename.
2024-05-03 10:21:03 -04:00

38 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require "livecheck/strategy"
RSpec.describe Homebrew::Livecheck::Strategy::Pypi do
subject(:pypi) { described_class }
let(:pypi_url) { "https://files.pythonhosted.org/packages/ab/cd/efg/example-package-1.2.3.tar.gz" }
let(:non_pypi_url) { "https://brew.sh/test" }
let(:generated) do
{
url: "https://pypi.org/project/example-package/#files",
regex: %r{href=.*?/packages.*?/example[_-]package[._-]v?(\d+(?:\.\d+)*(?:[._-]post\d+)?)\.t}i,
}
end
describe "::match?" do
it "returns true for a PyPI URL" do
expect(pypi.match?(pypi_url)).to be true
end
it "returns false for a non-PyPI URL" do
expect(pypi.match?(non_pypi_url)).to be false
end
end
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
end