Commits

Anonymous committed e72c84c

Added basic test for movie module

Comments (0)

Files changed (3)

Binary file added.

test/movie_test.py

-import unittest
-
-import test_utils
-from test_utils import test_not_implemented
-
-import pygame, pygame.movie
-
-class MovieTypeTest( unittest.TestCase ):    
-    def test_Movie(self):
-        # __doc__ (as of 2008-06-25) for pygame.movie.Movie:
-    
-          # pygame.movie.Movie(filename): return Movie
-          # pygame.movie.Movie(object): return Movie
-          # load an mpeg movie file
-    
-        self.assert_(test_not_implemented()) 
-
-if __name__ == '__main__':
+import unittest, os, sys
+
+import test_utils
+from test_utils import test_not_implemented
+
+import pygame, pygame.movie, time
+
+from pygame.locals import *
+
+# TODO fix bugs: checking to avoid segfaults
+
+class MovieTypeTest( unittest.TestCase ):            
+    def test_Movie(self):
+        # __doc__ (as of 2008-06-25) for pygame.movie.Movie:
+    
+          # pygame.movie.Movie(filename): return Movie
+          # pygame.movie.Movie(object): return Movie
+          # load an mpeg movie file
+
+        # pygame accepts only MPEG program stream containers, 
+        # with MPEG1 video and MPEG2 audio. I found
+        # that the command 
+        
+        # mencoder -of mpeg -ovc lavc -oac lavc -lavcopts \
+        # acodec=mp2:vcodec=mpeg1video:vbitrate=5000 -o new.mpg old.avi 
+        
+        # os.environ.update({"SDL_VIDEODRIVER":'windib'})
+        
+        pygame.display.init() # Needs to be init or will segfault
+        
+        movie_file = test_utils.trunk_relative_path('examples/data/blue.mpg')
+        movie = pygame.movie.Movie(movie_file)
+        movie_dimensions = movie.get_size()
+
+        self.assertEqual(movie_dimensions, (320, 240))
+
+        screen = pygame.display.set_mode(movie_dimensions)
+
+        movie.set_display(screen)
+        movie.render_frame(5)
+
+        self.assertEqual(screen.get_at((10,10)), (16, 16, 255, 255))
+
+        pygame.display.quit()
+
+#    def test_get_busy(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.get_busy:
+#
+#          # Movie.get_busy(): return bool
+#          # check if the movie is currently playing
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_get_frame(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.get_frame:
+#
+#          # Movie.get_frame(): return frame_number
+#          # get the current video frame
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_get_length(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.get_length:
+#
+#          # Movie.get_length(): return seconds
+#          # the total length of the movie in seconds
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_get_size(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.get_size:
+#
+#          # Movie.get_size(): return (width, height)
+#          # get the resolution of the video
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_get_time(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.get_time:
+#
+#          # Movie.get_time(): return seconds
+#          # get the current vide playback time
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_has_audio(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.has_audio:
+#
+#          # Movie.get_audio(): return bool
+#          # check if the movie file contains audio
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_has_video(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.has_video:
+#
+#          # Movie.get_video(): return bool
+#          # check if the movie file contains video
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_pause(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.pause:
+#
+#          # Movie.pause(): return None
+#          # temporarily stop and resume playback
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_play(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.play:
+#
+#          # Movie.play(loops=0): return None
+#          # start playback of a movie
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_render_frame(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.render_frame:
+#
+#          # Movie.render_frame(frame_number): return frame_number
+#          # set the current video frame
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_rewind(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.rewind:
+#
+#          # Movie.rewind(): return None
+#          # restart the movie playback
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_set_display(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.set_display:
+#
+#          # Movie.set_display(Surface, rect=None): return None
+#          # set the video target Surface
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_set_volume(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.set_volume:
+#
+#          # Movie.set_volume(value): return None
+#          # set the audio playback volume
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_skip(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.skip:
+#
+#          # Movie.skip(seconds): return None
+#          # advance the movie playback position
+#
+#        self.assert_(test_not_implemented()) 
+#
+#    def test_stop(self):
+#
+#        # __doc__ (as of 2008-07-18) for pygame.movie.Movie.stop:
+#
+#          # Movie.stop(): return None
+#          # stop movie playback
+#
+#        self.assert_(test_not_implemented()) 
+
+if __name__ == '__main__':
     unittest.main()

test/test_utils.py

 #################################### IMPORTS ###################################
 
-import tempfile, sys, pygame, unittest
+import tempfile, sys, pygame, unittest, time, os
+from test import pystone
 
 ############################### INCOMPLETE TESTS ###############################
 
 def get_tmp_dir():
     return tempfile.mkdtemp()
 
+################################################################################
+
+trunk_dir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
+
+def trunk_relative_path(relative):
+    return os.path.normpath(os.path.join(trunk_dir, relative))
+
+################################################################################
+
+# TOLERANCE in Pystones
+# kPS = 1000
+# TOLERANCE = 0.5*kPS 
+
+# class DurationError(AssertionError): pass
+
+# def local_pystone():
+#     return pystone.pystones(loops=pystone.LOOPS)
+
+# def timedtest(max_num_pystones, current_pystone=local_pystone()):
+#     """ decorator timedtest """
+#     if not isinstance(max_num_pystones, float):
+#         max_num_pystones = float(max_num_pystones)
+
+#     def _timedtest(function):
+#         def wrapper(*args, **kw):
+#             start_time = time.time()
+#             try:
+#                 return function(*args, **kw)
+#             finally:
+#                 total_time = time.time() - start_time
+#                 if total_time == 0:
+#                     pystone_total_time = 0
+#                 else:
+#                     pystone_rate = current_pystone[0] / current_pystone[1]
+#                     pystone_total_time = total_time / pystone_rate
+#                 if pystone_total_time > (max_num_pystones + TOLERANCE):
+#                     raise DurationError((('Test too long (%.2f Ps, '
+#                                         'need at most %.2f Ps)')
+#                                         % (pystone_total_time,
+#                                             max_num_pystones)))
+#         return wrapper
+
+#     return _timedtest
+
 #################################### HELPERS ###################################
 
 def rgba_between(value, minimum=0, maximum=255):
 if __name__ == '__main__':
     helpers_test()
 
-################################################################################
+################################################################################
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.