From 8f06ad8d4b4350285d5fad680a56703532602d0b Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sat, 5 Apr 2025 12:31:20 -0400 Subject: [PATCH] Remove ffmpeg from tests to speed up execution --- .github/workflows/test-and-deploy.yml | 5 ----- src/littlesongplace/__init__.py | 2 ++ test/conftest.py | 2 ++ test/test_songs.py | 17 ++++++++++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index a1894a3..70a2dd7 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -96,11 +96,6 @@ jobs: with: python-version: "3.11" - - name: Install ffmpeg - run: | - sudo apt update - sudo apt install ffmpeg - - name: Install mpck run: | wget https://github.com/Sjord/checkmate/releases/download/v0.21/mpck_0.21-1_amd64.deb diff --git a/src/littlesongplace/__init__.py b/src/littlesongplace/__init__.py index 5c3ff73..c8b7d08 100644 --- a/src/littlesongplace/__init__.py +++ b/src/littlesongplace/__init__.py @@ -396,7 +396,9 @@ def convert_song(tmp_file, request_file, yt_url): out_file.close() os.remove(out_file.name) result = subprocess.run(["ffmpeg", "-i", tmp_file.name, out_file.name], stdout=subprocess.PIPE) + print(result) if result.returncode == 0: + print('okie') # Successfully converted file, overwrite original file os.replace(out_file.name, tmp_file.name) return True diff --git a/test/conftest.py b/test/conftest.py index 224a295..182550b 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -8,6 +8,8 @@ import bcrypt import requests import pytest +pytest.register_assert_rewrite("test.utils") + from .utils import login fresh_db = None diff --git a/test/test_songs.py b/test/test_songs.py index 559fa99..9cd5f66 100644 --- a/test/test_songs.py +++ b/test/test_songs.py @@ -1,4 +1,6 @@ +import subprocess from pathlib import Path +from unittest import mock import pytest @@ -45,7 +47,20 @@ def test_upload_song_invalid_audio(client): # Use this script file as the "audio" file upload_song(client, b"Invalid audio file", error=True, filename=__file__) -def test_upload_song_from_mp4(client): +def _create_fake_mp3(*args, **kwargs): + subprocess_args = args[0] + if subprocess_args[0] == "ffmpeg": + # Create "fake" mp3 file by just copying input file + output_filename = subprocess_args[-1] + input_filename = subprocess_args[-2] + with open(input_filename, "rb") as infile, open(output_filename, "wb") as outfile: + outfile.write(infile.read()) + + return subprocess.CompletedProcess([], returncode=0, stdout=b"") + +@mock.patch("subprocess.run") +def test_upload_song_from_mp4(fake_run, client): + fake_run.side_effect = _create_fake_mp3 create_user(client, "user", "password", login=True) upload_song(client, b"Successfully uploaded 'song title'", filename=TEST_DATA/"sample-4s.mp4") -- 2.39.5