Skip to content

Commit

Permalink
new tests for audio functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
charliemacquarie committed Oct 30, 2023
1 parent da3b2a5 commit 73bcbaf
Showing 1 changed file with 168 additions and 0 deletions.
168 changes: 168 additions & 0 deletions tests/test_videogrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_duration(input_video):
stderr=subprocess.STDOUT
)

# FIX THIS - probably doesn't need float() x2
return float("{:.2f}".format(float(result.stdout)))


Expand Down Expand Up @@ -494,6 +495,173 @@ def test_sentence_search_vtt():
assert len(segments) == 0


def test_file_type():
videofile_1 = File("test_inputs/somevid.mp4")
assert videogrep.get_file_type(videofile_1) == "video"

videofile_2 = File("test_inputs/othervid.ogv")
assert videogrep.get_file_type(videofile_2) == "video"

audiofile_1 = File("test_inputs/someaudio.wav")
assert videogrep.get_file_type(audiofile_1) == "audio"

audiofile_2 = File("test_inputs/otheraudio.flac")
assert videogrep.get_file_type(audiofile_2) == "audio"

audiofile_3 = File("test_inputs/moreaudio.mp3")
assert videogrep.get_file_type(audiofile_3) == "audio"


def test_inputs_type():
segments_audio = [
{
"file": File("test_inputs/long-audio-wav.wav"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/audio.flac"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mp3"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

segments_mixed = [
{
"file": File("test_inputs/long-audio-wav.wav"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/audio.flac"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mov"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

segments_video = [
{
"file": File("test_inputs/bigvid.mp4"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/video.webm"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mov"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

assert videogrep.get_input_type(segments_audio) == "audio"
assert videogrep.get_input_type(segments_mixed) == "audio"
assert videogrep.get_input_type(segments_video) == "video"


def test_plans():
segments_audio = [
{
"file": File("test_inputs/long-audio-wav.wav"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/audio.flac"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mp3"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

segments_mixed = [
{
"file": File("test_inputs/long-audio-wav.wav"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/audio.flac"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mov"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

segments_video = [
{
"file": File("test_inputs/bigvid.mp4"),
"start": 548.97,
"end": 550.92,
"content": "on on the in the enemy right over there"
},
{
"file": File("test_inputs/video.webm"),
"start": 563.139082,
"end": 565.62,
"content": "over there at the filter going to rewriting"
},
{
"file": File("test_inputs/file.mov"),
"start": 754.965,
"end": 756.525,
"content": "i will be over the minute they were going"
}
]

video_output = File("test_outputs/somevideo.mp4")
audio_output = File("test_outputs/someaudio.mp3")
default_output = "supercut.mp4"

assert videogrep.plan_no_action(segments_audio, video_output) == True
# no action plan should let default video output filename come through
# and then audio output plan should kick in for all audio input
assert (
videogrep.plan_no_action(segments_audio, default_output) == False and
videogrep.plan_audio_output(segments_audio, default_output) == True
)
assert videogrep.plan_video_output(segments_video, video_output) == True
assert videogrep.plan_audio_output(segments_video, audio_output) == True
assert videogrep.plan_audio_output(segments_mixed, audio_output) == True
assert videogrep.plan_audio_output(segments_audio, audio_output) == True


def test_cli():
infile = File("test_inputs/manifesto.mp4")
outfile = File("test_outputs/supercut.mp4")
Expand Down

0 comments on commit 73bcbaf

Please sign in to comment.