Skip to content

Commit

Permalink
tests: Fix and Improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jan 21, 2024
1 parent 742e0d3 commit 1e4048a
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/artbox/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from abc import abstractmethod

from moviepy.editor import AudioFileClip, VideoFileClip
from pytube import YouTube
from pytube import YouTube as PyYouTube

from artbox.base import ArtBox

Expand All @@ -31,7 +31,7 @@ def download(self):
if not video_url:
raise Exception("Argument `url` not given.")

video = YouTube(video_url)
video = PyYouTube(video_url)

# Filter the stream by resolution if provided,
# else get the highest resolution
Expand Down
Binary file removed tests/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/audios/pixabay-science.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/notes/set1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["E", "D#", "E", "D#", "E", "B", "D", "C", "A"]
Binary file added tests/data/videos/pixabay-fuji.mp4
Binary file not shown.
71 changes: 45 additions & 26 deletions tests/test_sounds.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
"""Set of tests for the sounds module."""
import os
import unittest

from pathlib import Path

import pytest

from artbox.sounds import Sound

TMP_PATH = Path("/tmp/artbox")
TEST_DATA_DIR = Path(__file__).parent / "data"

os.makedirs(TMP_PATH, exist_ok=True)

@pytest.mark.fixture
def sound():
"""Create a fixture for the Sound object."""
return Sound()

def test_notes_to_audio():
"""Test the extraction of notes from mp3 file."""
mp3_path = TMP_PATH / "set1.mp3"
notes_path = TEST_DATA_DIR / "notes" / "set1.txt"

@pytest.mark.skip
def test_extract(sound):
"""Test the extraction audio from a video."""
videos_path = TMP_PATH / "Super Mario Theme EPIC VERSION.mp4"
output_path = TMP_PATH / "sounds" / "smb-epic-theme.mp3"
sound.extract_audio(str(videos_path), str(output_path))
params = {
"input-path": notes_path,
"output-path": mp3_path,
"duration": 2,
}
sound = Sound(params)
sound.notes_to_audio()


@pytest.mark.skip
def test_extract_notes_from_mp3(sound):
@unittest.skip("not fully implemented")
def test_extract_notes_from_mp3():
"""Test the extraction of notes from mp3 file."""
mp3_path = TMP_PATH / "sounds" / "tok-audio.mp3"
output_notes = TMP_PATH / "notes" / "tok-audio.txt"
notes = sound.extract_notes_from_mp3(str(mp3_path), str(output_notes))
filename = "pixabay-science"
mp3_path = TEST_DATA_DIR / "audio" / f"{filename}.mp3"
output_notes = TMP_PATH / "notes" / f"{filename}.txt"
params = {
"input-path": mp3_path,
"output-path": output_notes,
}
sound = Sound(params)
notes = sound.extract_notes_from_mp3()
print("Detected notes:", notes)


@pytest.mark.skip
def test_generate_melody(sound):
@unittest.skip("not fully implemented")
def test_generate_melody():
"""Test the melody generation from notes."""
notes_path = TMP_PATH / "notes" / "tok-audio.txt"
sound.generate_melody(notes_path, total_duration=3.54 * 60)
params = {
"input-path": notes_path,
"output-path": "/tmp/artbox/sound.mp3",
"duration": 3.54 * 60,
}
sound = Sound(params)
sound.generate_melody()


@pytest.mark.skip
def test_convert_to_8bit_audio(sound):
@unittest.skip("not fully implemented")
def test_convert_to_8bit_audio():
"""Test the audio conversion to 8bits style."""
videos_path = (
TMP_PATH
/ "videos"
/ "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4"
)
input_path = TEST_DATA_DIR / "audio" / "pixabay-science.mp3"
output_path = TMP_PATH / "sounds" / "tok8bits.mp3"
sound.convert_to_8bit_audio(str(videos_path), str(output_path))
params = {
"input-path": mp3_path,
"output-path": output_notes,
}
sound = Sound(params)
sound.convert_to_8bit_audio()
65 changes: 39 additions & 26 deletions tests/test_videos.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
"""Set of tests for the videos module."""
import os

from pathlib import Path

import pytest

from artbox.videos import Video
from artbox.videos import Video, Youtube

TMP_PATH = Path("/tmp/artbox")

TMP_PATH = Path("/tmp/artbox")
TEST_DATA_DIR = Path(__file__).parent / "data"

@pytest.mark.fixture
def video():
"""Create a fixture for the Video object."""
return Video()
os.makedirs(TMP_PATH, exist_ok=True)


@pytest.mark.skip
def test_combine_video_and_audio(video):
def test_combine_video_and_audio():
"""Test the function that combines video and audio."""
# Example usage
# "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4"
video_path = TMP_PATH / "peachs-no-audio.mp4"
audio_path = TMP_PATH / "smb-epic-theme.mp3"
output_path = TMP_PATH / "peachs-with-music.mp4"
video.combine_video_and_audio(
str(video_path), str(audio_path), str(output_path)
)
video_path = TEST_DATA_DIR / "videos" / "pixabay-fuji.mp4"
audio_path = TEST_DATA_DIR / "audios" / "pixabay-science.mp3"
output_path = TMP_PATH / "video+audio.mp4"

params = {
"video-path": str(video_path),
"audio-path": str(audio_path),
"output-path": str(output_path),
}
video = Video(params)
video.combine_video_and_audio()


@pytest.mark.skip
def test_download_from_youtube(video):
def test_download_from_youtube():
"""Test the method that downloads videos from youtube."""
# "https://www.youtube.com/watch?v=uHGShqcAHlQ"
for url in [
"https://youtube.com/shorts/gmutDetnBLQ",
"https://youtube.com/watch?v=6pjbaE98ftU",
]:
video.download_from_youtube(url)


@pytest.mark.skip
def test_remove_audio(video):
for i, url in enumerate(
[
"https://youtube.com/shorts/gmutDetnBLQ",
"https://youtube.com/watch?v=6pjbaE98ftU",
]
):
params = {"output-path": TMP_PATH, "url": url}
youtube = Youtube(params)
youtube.download()


def test_remove_audio():
"""Test the function that removes audio from a video."""
input_file = TMP_PATH / (
"Princess Peachs Training Course in The Super Mario Bros Movie.mp4"
)
output_file = "peachs-no-audio.mp4"
video.remove_audio(input_file, TMP_PATH / output_file)

params = {
"input-path": TEST_DATA_DIR / "videos" / "pixabay-fuji.mp4",
"output-path": TMP_PATH / "video-with-no-audio.mp4",
}

video = Video(params)
video.remove_audio()

0 comments on commit 1e4048a

Please sign in to comment.