@@ -29,7 +29,10 @@ def formula_auditor(name, text, options = {})
2929
3030 if options . key? :tap_audit_exceptions
3131 tap = Tap . fetch ( "test/tap" )
32- allow ( tap ) . to receive ( :audit_exceptions ) . and_return ( options [ :tap_audit_exceptions ] )
32+ allow ( tap ) . to receive_messages (
33+ audit_exceptions : options [ :tap_audit_exceptions ] ,
34+ pypi_dependencies_formulae : options [ :pypi_dependencies_formulae ] || [ ] ,
35+ )
3336 allow ( formula ) . to receive ( :tap ) . and_return ( tap )
3437 options . delete :tap_audit_exceptions
3538 end
@@ -526,6 +529,8 @@ class Foo < Formula
526529 end
527530
528531 describe "#audit_pypi_resources" do
532+ let ( :pypi_dependencies_formulae ) { [ "bar" , "baz" ] }
533+
529534 it "reports a problem if the resource name does not match the python sdist name" do
530535 fa = formula_auditor "foo" , <<~RUBY
531536 class Foo < Formula
@@ -565,19 +570,19 @@ class Foo < Formula
565570 end
566571
567572 it "reports a problem if the resource should be replaced with a dependency" do
568- fa = formula_auditor "foo" , <<~RUBY
573+ fa = formula_auditor ( "foo" , <<~RUBY , tap_audit_exceptions : { } , pypi_dependencies_formulae : )
569574 class Foo < Formula
570575 url "https://brew.sh/foo-1.0.tgz"
571576 sha256 "abc123"
572577 homepage "https://brew.sh"
573578
574- resource "cryptography " do
575- url "https://files.pythonhosted.org/packages/00/00/aaaa/cryptography -1.0.0.tar.gz"
579+ resource "bar " do
580+ url "https://files.pythonhosted.org/packages/00/00/aaaa/bar -1.0.0.tar.gz"
576581 sha256 "def456"
577582 end
578583
579- resource "pydantic " do
580- url "https://files.pythonhosted.org/packages/00/00/aaaa/pydantic -1.0.0.tar.gz"
584+ resource "baz " do
585+ url "https://files.pythonhosted.org/packages/00/00/aaaa/baz -1.0.0.tar.gz"
581586 sha256 "ghi789"
582587 end
583588 end
@@ -586,24 +591,25 @@ class Foo < Formula
586591 fa . audit_specs
587592 expect ( fa . problems . count ) . to eq ( 2 )
588593 expect ( fa . problems . first [ :message ] )
589- . to match ( "PyPI package should be replaced with Homebrew dependency and excluded using `pypi_package` method" )
594+ . to match ( "PyPI package should be replaced with `depends_on \" bar\" ` " \
595+ "and excluded using `pypi_package` method" )
590596 end
591597
592598 it "doesn't report a problem if there is an exception to a PyPI resource that should be a dependency" do
593- tap_audit_exceptions = { pypi_resources_allowlist : { "foo" => "cryptography pydantic " } }
594- fa = formula_auditor ( "foo" , <<~RUBY , tap_audit_exceptions :)
599+ tap_audit_exceptions = { pypi_resources_allowlist : { "foo" => "bar baz " } }
600+ fa = formula_auditor ( "foo" , <<~RUBY , tap_audit_exceptions :, pypi_dependencies_formulae : )
595601 class Foo < Formula
596602 url "https://brew.sh/foo-1.0.tgz"
597603 sha256 "abc123"
598604 homepage "https://brew.sh"
599605
600- resource "cryptography " do
601- url "https://files.pythonhosted.org/packages/60/04 /aaaa/cryptography -1.0.0.tar.gz"
606+ resource "bar " do
607+ url "https://files.pythonhosted.org/packages/00/00 /aaaa/bar -1.0.0.tar.gz"
602608 sha256 "def456"
603609 end
604610
605- resource "pydantic " do
606- url "https://files.pythonhosted.org/packages/00/00/aaaa/pydantic -1.0.0.tar.gz"
611+ resource "baz " do
612+ url "https://files.pythonhosted.org/packages/00/00/aaaa/baz -1.0.0.tar.gz"
607613 sha256 "ghi789"
608614 end
609615 end
@@ -614,9 +620,9 @@ class Foo < Formula
614620 end
615621
616622 it "doesn't audit PyPI package if it is not a resource" do
617- fa = formula_auditor "cryptography ", <<~RUBY
618- class Cryptography < Formula
619- url "https://files.pythonhosted.org/packages/60/04 /aaaa/cryptography -1.0.0.tar.gz"
623+ fa = formula_auditor ( "bar ", <<~RUBY , tap_audit_exceptions : { } , pypi_dependencies_formulae : )
624+ class Bar < Formula
625+ url "https://files.pythonhosted.org/packages/00/00 /aaaa/bar -1.0.0.tar.gz"
620626 sha256 "abc123"
621627 homepage "https://brew.sh"
622628 end
0 commit comments