Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests of autoprocessing #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
40 changes: 40 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on: [push]

jobs:
test:
name: Run tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [2.7, 3.8]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
# pip install -r requirements.txt
- name: Install FFmpeg (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get update
sudo apt-get install ffmpeg
- name: Install FFmpeg (Windows)
if: startsWith(matrix.os, 'windows')
run: choco install ffmpeg
- name: Install FFmpeg (macOS)
if: startsWith(matrix.os, 'macos')
run: brew install ffmpeg
- name: Test with pytest
run: |
pip install pytest pytest-timeout
pytest
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: push
jobs:
test:
name: Deploy release to PyPI
if: github.repository == 'philipstarkey/autoscrub'
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
click>=6.0,<7.0
six
requests
subprocess32; python_version < '3.2'
subprocess32; python_version < '3.2'
pathlib2; python_version < '3'
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool:pytest]
testpaths = tests
timeout = 150
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
'six',
'requests',
'subprocess32;python_version<"3.2"',
'pathlib2;python_version<"3"'
],
entry_points='''
[console_scripts]
Expand Down
Binary file added tests/example_screencast.mp4
Binary file not shown.
28 changes: 28 additions & 0 deletions tests/example_screencast.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[0:v]trim=0.0000:0.2530,setpts=PTS-STARTPTS[v1];
[0:v]trim=0.2530:1.9990,setpts=(PTS-STARTPTS)/8[v2];
[0:v]trim=1.9990:6.4611,setpts=PTS-STARTPTS[v3];
[0:v]trim=6.4611:16.8058,setpts=(PTS-STARTPTS)/8[v4];
[0:v]trim=16.8058:19.3400,setpts=PTS-STARTPTS[v5];
[0:v]trim=19.3400:32.5301,setpts=(PTS-STARTPTS)/8[v6];
[0:v]trim=32.5301:45.8549,setpts=PTS-STARTPTS[v7];
[0:v]trim=45.8549:56.1694,setpts=(PTS-STARTPTS)/8[v8];
[0:v]trim=56.1694:59.8605,setpts=PTS-STARTPTS[v9];
[0:v]trim=59.8605:64.8073,setpts=(PTS-STARTPTS)/8[v10];
[0:v]trim=64.8073:78.2927,setpts=PTS-STARTPTS[v11];
[0:v]trim=78.2927:81.6206,setpts=(PTS-STARTPTS)/8[v12];
[0:v]trim=start=81.6206,setpts=PTS-STARTPTS[v13];
[0:a]atrim=0.0000:0.2530,asetpts=PTS-STARTPTS[a1];
[0:a]atrim=0.2530:1.9990,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a2];
[0:a]atrim=1.9990:6.4611,asetpts=PTS-STARTPTS[a3];
[0:a]atrim=6.4611:16.8058,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a4];
[0:a]atrim=16.8058:19.3400,asetpts=PTS-STARTPTS[a5];
[0:a]atrim=19.3400:32.5301,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a6];
[0:a]atrim=32.5301:45.8549,asetpts=PTS-STARTPTS[a7];
[0:a]atrim=45.8549:56.1694,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a8];
[0:a]atrim=56.1694:59.8605,asetpts=PTS-STARTPTS[a9];
[0:a]atrim=59.8605:64.8073,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a10];
[0:a]atrim=64.8073:78.2927,asetpts=PTS-STARTPTS[a11];
[0:a]atrim=78.2927:81.6206,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a12];
[0:a]atrim=start=81.6206,asetpts=PTS-STARTPTS[a13];
[v1][a1][v2][a2][v3][a3][v4][a4][v5][a5][v6][a6][v7][a7][v8][a8][v9][a9][v10][a10][v11][a11][v12][a12][v13][a13]concat=n=13:v=1:a=1[v][an];
[an]volume=4.8dB[a]
81 changes: 81 additions & 0 deletions tests/test_example_screencast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import filecmp
import six
import autoscrub

if six.PY3:
from pathlib import Path
else:
# backported pathlib module
from pathlib2 import Path

TEST_VIDEO_INPUT = "example_screencast.mp4"
TEST_VIDEO_OUTPUT = "example_screencast_scrub.mp4"
VALID_FILTERGRAPH = "example_screencast.txt"
VALID_DURATION = 48.57
VALID_LOUDNESS = {
"I": -18.1,
"Threshold": -39.2,
"LRA": 7.3,
"LRA low": -23.5,
"LRA high": -16.2,
}


os.chdir(str(Path(__file__).parent.absolute()))


def cmp_lines(path_1, path_2):
"""Check file equality using universal line endings.
See: https://stackoverflow.com/a/23038606
"""
l1 = l2 = True
with open(path_1, "r") as f1, open(path_2, "r") as f2:
while l1 and l2:
l1 = f1.readline()
l2 = f2.readline()
if l1 != l2:
return False
return True


def test_autoprocess(input=TEST_VIDEO_INPUT, filtergraph=VALID_FILTERGRAPH):
"""Runs autoscrub autoprocess --debug on TEST_VIDEO_INPUT

Checks stdout and compares resulting filtergraph to known valid version
"""
# Create output path
suffix = Path(input).suffix
output = input.replace(suffix, "_scrub" + suffix)

# Run autoscrub autoprocess --debug input output
p = autoscrub._agnostic_Popen(
["autoscrub", "autoprocess", "--debug", input, output]
)
_, stderr = autoscrub._agnostic_communicate(p)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #2 in which processing continued indefinitely, a timeout is essential here, akin to subprocess.Popen.communicate. @philipstarkey, is this something that could/should be added to autoscrub._agnostic_communicate or should I be using something else. here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I've set a timeout on the test runner, using pytest-timeout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, but the test is stalling on Windows at this point (both locally and on Python 2.7 and 3.8).


# Check stdout
stdout = p.stdout.readlines()
assert stdout[-4].strip() == b"[autoscrub:info] Done!"

# Check filtergraph
tmp = Path(stdout[-1].decode("utf8").split("at:")[-1].strip())
assert cmp_lines(VALID_FILTERGRAPH, str(tmp))


def test_duration():
"""Checks duration of processed test video

Checks duration of processed test video produced by autoscrub autoprocess
is as expected.
"""
assert autoscrub.getDuration(TEST_VIDEO_OUTPUT) == VALID_DURATION


def test_loudness():
"""Checks loudness properties of processed test video

Checks loudness of test video produced by autoscrub autoprocess
is as expected.
"""
assert autoscrub.getLoudness(TEST_VIDEO_OUTPUT) == VALID_LOUDNESS