Skip to content

Commit

Permalink
Use pytest instead of setup.py
Browse files Browse the repository at this point in the history
Also run audioresampler test
  • Loading branch information
WyattBlue committed Jul 31, 2024
1 parent b2193fd commit c13166f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 56 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ LDFLAGS ?= ""
CFLAGS ?= "-O0"

PYAV_PYTHON ?= python
PYAV_PIP ?= pip
PYTHON := $(PYAV_PYTHON)
PIP := $(PYAV_PIP)


.PHONY: default build clean fate-suite lint test
Expand All @@ -11,6 +13,8 @@ default: build


build:
# Always try to install the Python dependencies they are cheap.
$(PIP) install --upgrade -r tests/requirements.txt
CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) $(PYTHON) setup.py build_ext --inplace --debug

clean:
Expand All @@ -25,10 +29,12 @@ fate-suite:
rsync -vrltLW rsync://fate-suite.ffmpeg.org/fate-suite/ tests/assets/fate-suite/

lint:
$(PIP) install --upgrade -r tests/requirements.txt
black --check av examples tests setup.py
flake8 av examples tests
isort --check-only --diff av examples tests
mypy av tests

test:
$(PYTHON) setup.py test
$(PIP) install --upgrade -r tests/requirements.txt
$(PYTHON) -m pytest
9 changes: 6 additions & 3 deletions scripts/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ fi
export PYAV_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)"

if [[ ! "$PYAV_LIBRARY" ]]; then

# Pull from command line argument.
if [[ "$1" ]]; then
PYAV_LIBRARY="$1"
if [[ "$1" == ffmpeg-* ]]; then
PYAV_LIBRARY="$1"
else
echo "Error: PYAV_LIBRARY must start with 'ffmpeg-'" >&2
return 1
fi
else
PYAV_LIBRARY=ffmpeg-7.0.1
echo "No \$PYAV_LIBRARY set; defaulting to $PYAV_LIBRARY"
Expand Down
6 changes: 1 addition & 5 deletions scripts/build-deps
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ fi

cd "$PYAV_ROOT"

# Always try to install the Python dependencies they are cheap.
$PYAV_PIP install --upgrade -r tests/requirements.txt


# Skip the rest of the build if it already exists.
if [[ -e "$PYAV_LIBRARY_PREFIX/bin/ffmpeg" ]]; then
echo "We have a cached build of $PYAV_LIBRARY; skipping re-build."
echo "We have a cached build of ffmpeg-$PYAV_LIBRARY; skipping re-build."
exit 0
fi

Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ black
isort
flake8
flake8-pyproject
pytest
sphinx==5.1.0
mypy==1.10.0
95 changes: 48 additions & 47 deletions tests/test_audioresampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,53 +68,54 @@ def test_matching_passthrough(self):
oframes = resampler.resample(None)
self.assertEqual(len(oframes), 0)

# TODO: Fails on ffmpeg 6
# def test_pts_assertion_same_rate(self):
# av.logging.set_level(av.logging.VERBOSE)
# resampler = AudioResampler("s16", "mono")

# # resample one frame
# iframe = AudioFrame("s16", "stereo", 1024)
# iframe.sample_rate = 48000
# iframe.time_base = "1/48000"
# iframe.pts = 0

# oframes = resampler.resample(iframe)
# self.assertEqual(len(oframes), 1)

# oframe = oframes[0]
# self.assertEqual(oframe.pts, 0)
# self.assertEqual(oframe.time_base, iframe.time_base)
# self.assertEqual(oframe.sample_rate, iframe.sample_rate)
# self.assertEqual(oframe.samples, iframe.samples)

# # resample another frame
# iframe.pts = 1024

# oframes = resampler.resample(iframe)
# self.assertEqual(len(oframes), 1)

# oframe = oframes[0]
# self.assertEqual(oframe.pts, 1024)
# self.assertEqual(oframe.time_base, iframe.time_base)
# self.assertEqual(oframe.sample_rate, iframe.sample_rate)
# self.assertEqual(oframe.samples, iframe.samples)

# # resample another frame with a pts gap, do not raise exception
# iframe.pts = 9999
# oframes = resampler.resample(iframe)
# self.assertEqual(len(oframes), 1)

# oframe = oframes[0]
# self.assertEqual(oframe.pts, 9999)
# self.assertEqual(oframe.time_base, iframe.time_base)
# self.assertEqual(oframe.sample_rate, iframe.sample_rate)
# self.assertEqual(oframe.samples, iframe.samples)

# # flush
# oframes = resampler.resample(None)
# self.assertEqual(len(oframes), 0)
# av.logging.set_level(None)
def test_pts_assertion_same_rate(self):
import av

av.logging.set_level(av.logging.VERBOSE)
resampler = AudioResampler("s16", "mono")

# resample one frame
iframe = AudioFrame("s16", "stereo", 1024)
iframe.sample_rate = 48000
iframe.time_base = "1/48000"
iframe.pts = 0

oframes = resampler.resample(iframe)
self.assertEqual(len(oframes), 1)

oframe = oframes[0]
self.assertEqual(oframe.pts, 0)
self.assertEqual(oframe.time_base, iframe.time_base)
self.assertEqual(oframe.sample_rate, iframe.sample_rate)
self.assertEqual(oframe.samples, iframe.samples)

# resample another frame
iframe.pts = 1024

oframes = resampler.resample(iframe)
self.assertEqual(len(oframes), 1)

oframe = oframes[0]
self.assertEqual(oframe.pts, 1024)
self.assertEqual(oframe.time_base, iframe.time_base)
self.assertEqual(oframe.sample_rate, iframe.sample_rate)
self.assertEqual(oframe.samples, iframe.samples)

# resample another frame with a pts gap, do not raise exception
iframe.pts = 9999
oframes = resampler.resample(iframe)
self.assertEqual(len(oframes), 1)

oframe = oframes[0]
self.assertEqual(oframe.pts, 9999)
self.assertEqual(oframe.time_base, iframe.time_base)
self.assertEqual(oframe.sample_rate, iframe.sample_rate)
self.assertEqual(oframe.samples, iframe.samples)

# flush
oframes = resampler.resample(None)
self.assertEqual(len(oframes), 0)
av.logging.set_level(None)

def test_pts_assertion_new_rate_up(self):
resampler = AudioResampler("s16", "mono", 44100)
Expand Down

0 comments on commit c13166f

Please sign in to comment.