# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-betamax
pkgver=0.9.0
pkgrel=7
pkgdesc="A VCR imitation for python-requests"
arch=('any')
license=('Apache-2.0')
url='https://github.com/betamaxpy/betamax'
depends=('python' 'python-requests')
makedepends=('python-build' 'python-installer' 'python-wheel' 'python-setuptools')
checkdepends=('python-pytest')
source=(
  "https://github.com/betamaxpy/betamax/archive/$pkgver/$pkgname-$pkgver.tar.gz"
  "$pkgname-urllib3-2.0-compatibility.patch"
)
sha512sums=('6a85f21dd7ccd0d53e6c87ff4f159d295d40729098c13c435c1715252e4cbbeabb82e6347e84a16094f13a1a0249dd1c067ddc82fd36c292913ecbdb22148371'
            'c683b1383ea10e3c8408a0ec104daf11b6e1e49ff087732d189319dd873472936a969801b2dbbef6c4abb4213a99473bf10063e69ee04f7f47d4c1d56f0d0c6e')

prepare() {
  cd betamax-$pkgver
  # Disable some failing tests; taken from Gentoo
  sed -i -e 's:test_records:_&:' -e 's:test_replaces:_&:' -e 's:test_replays:_&:' \
    tests/integration/test_record_modes.py

  # httpbin flaky at best. 
  sed -i -e 's:test_placeholders_work:_&:' tests/integration/test_placeholders.py
  sed -i -e 's:test_requests_with_json_body:_&:' tests/regression/test_requests_2_11_body_matcher.py

  patch -Np1 < ../$pkgname-urllib3-2.0-compatibility.patch
}

build() {
  cd betamax-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd betamax-$pkgver
  PYTHONPATH="$PWD/src" pytest
}

package() {
  cd betamax-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
}
