Skip to content

Commit

Permalink
tests: Added video and audio tests
Browse files Browse the repository at this point in the history
Closes #663
  • Loading branch information
FReeshabh authored and rdb committed Feb 7, 2023
1 parent fc2ef74 commit dcd2aa8
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
Binary file added tests/movies/impulse.flac
Binary file not shown.
Binary file added tests/movies/small.mp4
Binary file not shown.
58 changes: 58 additions & 0 deletions tests/movies/test_movie_audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from panda3d.core import MovieAudioCursor
from panda3d.core import MovieAudio
from panda3d.core import Filename
from panda3d.core import PandaSystem
from panda3d.core import MovieTexture
from panda3d.core import MovieVideo

import pytest
import os


def test_audio_rate(): #tests for audio rate
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path) # enables Platform independent testing
reference_file = MovieAudio.get(movie_path)
movie_file = reference_file.open()
assert movie_file.audio_rate() == 48000


def test_audio_length(): #test for testing audio length
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieAudio.get(movie_path)
movie_file = reference_file.open()
assert movie_file.length() == 2


def test_can_seek(): #test for seeking
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieAudio.get(movie_path)
movie_file = reference_file.open()
assert movie_file.can_seek() is True


def test_can_seek_fast(): #test for seeking fast
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieAudio.get(movie_path)
movie_file = reference_file.open()
assert movie_file.can_seek_fast() is True


def test_audio_channel(): #tests for number of audio channels
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieAudio.get(movie_path)
movie_file = reference_file.open()
assert movie_file.audio_channels() == 1


def test_cursor(): #opening the file returns a cursor
movie_path = os.path.join(os.path.dirname(__file__), "impulse.flac")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieAudio.get(movie_path)
file_name_return = reference_file.get_filename()
assert reference_file.open() is not None #checks the cursor
assert file_name_return == movie_path #checks the return name of the file
52 changes: 52 additions & 0 deletions tests/movies/test_movie_texture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from panda3d.core import MovieVideo
from panda3d.core import MovieTexture
from panda3d.core import Filename
from panda3d.core import PandaSystem
from panda3d.core import MovieTexture

import pytest
import os


def check_ffmpeg():
# Make sure video plug-ins are loaded
MovieVideo.get("test.mp4")

system = PandaSystem.get_global_ptr()
return 'FFmpeg' in system.systems #checks whether ffmpeg is loaded


@pytest.mark.skipif(not check_ffmpeg(), reason="skip when ffmpeg is not available")
class Test_Texture_Movie():
def test_texture_loop_count(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path) # enables Platform independent testing
reference_file = MovieVideo.get(movie_path)
reference_texture = MovieTexture(reference_file)
assert reference_texture.get_loop_count() == 1

def test_video_is_playing(self): #This test checks isPlaying() and stop() functionality
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path) # enables Platform independent testing
reference_file = MovieVideo.get(movie_path)
reference_texture = MovieTexture(reference_file)
reference_texture.play()
assert reference_texture.is_playing() is True
reference_texture.stop()
assert reference_texture.is_playing() is False

def test_play_rate(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path) # enables Platform independent testing
reference_file = MovieVideo.get(movie_path)
reference_texture = MovieTexture(reference_file)
assert reference_texture.get_play_rate() == 1
reference_texture.set_play_rate(2)
assert reference_texture.get_play_rate() == 2

def test_video_texture_length(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path) # enables Platform independent testing
reference_file = MovieVideo.get(movie_path)
reference_texture = MovieTexture(reference_file)
assert reference_texture.get_video_length() == 32.480 #got info from mkvinfo
39 changes: 39 additions & 0 deletions tests/movies/test_movie_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from panda3d.core import MovieVideo
from panda3d.core import Filename
from panda3d.core import PandaSystem

import pytest
import os


def check_ffmpeg():
# Make sure video plug-ins are loaded
MovieVideo.get("test.mp4")

system = PandaSystem.get_global_ptr()
return 'FFmpeg' in system.systems #checks whether ffmpeg is loaded


@pytest.mark.skipif(not check_ffmpeg(), reason="skip when ffmpeg is not available")
class Test_Video_Movie():
def test_cursor_check(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieVideo.get(movie_path)
assert reference_file.get_filename() == movie_path
assert reference_file.open() is not None

def test_video_length(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieVideo.get(movie_path)
cursor = reference_file.open()
assert cursor.length() == 32.4800

def test_video_size(self):
movie_path = os.path.join(os.path.dirname(__file__), "small.mp4")
movie_path = Filename.from_os_specific(movie_path)
reference_file = MovieVideo.get(movie_path)
cursor = reference_file.open()
assert cursor.size_x() == 640 #found the height and width using mkvinfo
assert cursor.size_y() == 360

0 comments on commit dcd2aa8

Please sign in to comment.