Commits

Anonymous committed 7ae13de

Merged to trunk revision 2231

  • Participants
  • Parent commits 75ebbd4
  • Branches tylerthemovie

Comments (0)

Files changed (2)

 MIDIOUT = pygame.locals.USEREVENT + 11
 
 _init = False
-
+pypm = None
 
 
 def init():
         _init = True
         atexit.register(quit)
 
+
+
 def quit():
     """uninitialize the midi module
     pygame.midi.quit(): return None
         pypm.Terminate()
         _init = False
         del pypm
-        del pygame.pypm
+        #del pygame.pypm
 
-
-
+def _check_init():
+    if not _init:
+        raise RuntimeError("pygame.midi not initialised.")
 
 def get_count():
     """gets the number of devices.
 
     Device ids range from 0 to get_count() -1
     """
+    _check_init()
     return pypm.CountDevices()
 
 

test/midi_test.py

     from test import test_utils
     from test.test_utils import test_not_implemented, unittest
 import pygame
-import pygame.movie
+import pygame.midi
 from pygame.locals import *
 
+
 import os
 import sys
 import time
 
 
+
+
+
 class MidiTest( unittest.TestCase ):            
 
     def todo_test_poll(self):
 
         self.fail() 
 
-    def todo_test_get_count(self):
+
+    def tearDown(self):
+        pygame.midi.quit()
+
+    def setUp(self):
+        pygame.midi.init()
+
+    def test_get_count(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.get_count:
 
           # 
           # Device ids range from 0 to get_count() -1
 
-        self.fail() 
+        c = pygame.midi.get_count()
+        self.assertEqual(type(c), type(1))
+        self.failUnless(c >= 0)
 
-    def todo_test_get_default_input_device_id(self):
+
+
+    def test_get_default_input_device_id(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.get_default_input_device_id:
 
           # Note: in the current release, the default is simply the first device
           #     (the input or output device with the lowest PmDeviceID).
 
-        self.fail() 
+        c = pygame.midi.get_default_input_device_id() 
+        self.assertEqual(type(c), type(1))
+        self.failUnless(c >= 0)
 
-    def todo_test_get_default_output_device_id(self):
+
+    def test_get_default_output_device_id(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.get_default_output_device_id:
 
           # Note: in the current release, the default is simply the first device
           #     (the input or output device with the lowest PmDeviceID).
 
-        self.fail() 
+        c = pygame.midi.get_default_output_device_id() 
+        self.assertEqual(type(c), type(1))
+        self.failUnless(c >= 0)
 
-    def todo_test_get_device_info(self):
+
+
+
+    def test_get_device_info(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.get_device_info:
 
           # 
           # If the id is out of range, the function returns None.
 
-        self.fail() 
+        an_id = pygame.midi.get_default_output_device_id() 
+        interf, name, input, output, opened = pygame.midi.get_device_info(an_id)
+        self.assertEqual(output, 1)
+        self.assertEqual(input, 0)
+        self.assertEqual(opened, 0)
 
-    def todo_test_init(self):
+
+        an_in_id = pygame.midi.get_default_input_device_id() 
+        interf, name, input, output, opened = pygame.midi.get_device_info(an_in_id)
+        self.assertEqual(output, 0)
+        self.assertEqual(input, 1)
+        self.assertEqual(opened, 0)
+
+
+
+
+
+
+    def test_init(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.init:
 
           # Call the initialisation function before using the midi module.
           # 
           # It is safe to call this more than once.
+        pygame.midi.quit()
+        self.assertRaises(RuntimeError, pygame.midi.get_count)
+        # initialising many times should be fine.
+        pygame.midi.init()
+        pygame.midi.init()
+        pygame.midi.init()
+        pygame.midi.init()
 
-        self.fail() 
+
 
     def todo_test_midis2events(self):
 
 
         self.fail() 
 
-    def todo_test_quit(self):
+    def test_quit(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.quit:
 
           # 
           # It is safe to call this function more than once.
 
-        self.fail() 
 
-    def todo_test_time(self):
+          # It is safe to call this more than once.
+        pygame.midi.quit()
+        pygame.midi.init()
+        pygame.midi.quit()
+        pygame.midi.quit()
+        pygame.midi.init()
+        pygame.midi.init()
+        pygame.midi.quit()
+
+    def test_time(self):
 
         # __doc__ (as of 2009-05-19) for pygame.midi.time:
 
           # returns the current time in ms of the PortMidi timer
           # pygame.midi.time(): return time
 
-        self.fail() 
+        t = pygame.midi.time()
+        self.assertEqual(type(t), type(1))
+        # should be close to 2-3... since the timer is just init'd.
+        self.failUnless(t >= 0 and t < 100)
+
 
  
 if __name__ == '__main__':