-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ivansaul/feature/implement-tests
feat: add basic unit tests
- Loading branch information
Showing
9 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- '*.md' | ||
|
||
jobs: | ||
release: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '*.md' | ||
|
||
branches: | ||
- develop | ||
|
||
pull_request: | ||
paths-ignore: | ||
- '*.md' | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
python-version: ["3.10"] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Setup | Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Poetry | ||
shell: bash | ||
run: pipx install poetry | ||
|
||
- name: Install FFmpeg | ||
uses: AnimMouse/setup-ffmpeg@v1 | ||
with: | ||
version: master | ||
|
||
- name: Setup | Install Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'poetry' | ||
|
||
- name: Install Dependencies | ||
run: poetry install --with=dev | ||
|
||
- name: Lint with Ruff | ||
run: poetry run ruff check --output-format=github . | ||
|
||
- name: Run Tests with Pytest | ||
run: poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Custom | ||
tmp/ | ||
*.mp4 | ||
!src/tests/resources/sample*.mp4 | ||
.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
}, | ||
"cSpell.words": [ | ||
"acodec", | ||
"autouse", | ||
"ffprobe", | ||
"github", | ||
"ivansaul", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from typer.testing import CliRunner | ||
|
||
from vidpack.cli import app | ||
|
||
runner = CliRunner() | ||
|
||
PROGRESS_COMPLETION_OUTPUT = "100% 0:00:00" | ||
|
||
TEST_VIDEOS_PATH: Path = Path(__file__).parent / "resources" | ||
INPUT: str = str(TEST_VIDEOS_PATH / "sample_video_1.mp4") | ||
INPUT_2: str = str(TEST_VIDEOS_PATH / "sample_video_2.mp4") | ||
OUTPUT: str = str(TEST_VIDEOS_PATH / "output.mp4") | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def setup_teardown(): | ||
""" | ||
Fixture to setup and teardown the test environment. | ||
""" | ||
yield | ||
for file in TEST_VIDEOS_PATH.glob("*_compressed.mp4"): | ||
os.remove(file) | ||
|
||
|
||
def test_single_file_compression_with_default_options(): | ||
""" | ||
Test single file compression with default options. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout | ||
|
||
|
||
@pytest.mark.parametrize("codec", ["h264", "libx265"]) | ||
def test_single_file_compression(codec): | ||
""" | ||
Test single file compression with different video codecs. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT, "--codec", codec]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout | ||
|
||
|
||
@pytest.mark.parametrize("codec", ["libx267", "123"]) | ||
def test_single_file_compression_with_invalid_codec(codec): | ||
""" | ||
Test single file compression with invalid video codec. | ||
Expected results: | ||
- Exit code: 2 | ||
""" | ||
result = runner.invoke(app, [INPUT, "--codec", codec]) | ||
assert result.exit_code == 2, result.stdout | ||
|
||
|
||
def test_single_file_compression_with_quality_option(): | ||
""" | ||
Test single file compression with quality option. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT, "--quality", "50"]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout | ||
|
||
|
||
def test_single_file_compression_with_overwrite_option(): | ||
""" | ||
Test single file compression with overwrite option. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT, "--overwrite"]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout | ||
|
||
|
||
def test_single_file_compression_with_delete_original_option(): | ||
""" | ||
Test single file compression with delete original option. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT_2, "--delete-original"]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout | ||
|
||
|
||
def test_single_file_compression_with_output_option(): | ||
""" | ||
Test single file compression with output option. | ||
Expected results: | ||
- Exit code: 0 | ||
- Progress completion output: "100% 0:00:00" | ||
""" | ||
result = runner.invoke(app, [INPUT, "--output", OUTPUT]) | ||
assert result.exit_code == 0, result.stdout | ||
assert PROGRESS_COMPLETION_OUTPUT in result.stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters