cdrom_test.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import unittest
  2. from pygame.tests.test_utils import question, prompt
  3. import pygame
  4. pygame.cdrom.init()
  5. # The number of CD drives available for testing.
  6. CD_DRIVE_COUNT = pygame.cdrom.get_count()
  7. pygame.cdrom.quit()
  8. class CDROMModuleTest(unittest.TestCase):
  9. def setUp(self):
  10. pygame.cdrom.init()
  11. def tearDown(self):
  12. pygame.cdrom.quit()
  13. def todo_test_CD(self):
  14. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD:
  15. # pygame.cdrom.CD(id): return CD
  16. # class to manage a cdrom drive
  17. #
  18. # You can create a CD object for each cdrom on the system. Use
  19. # pygame.cdrom.get_count() to determine how many drives actually
  20. # exist. The id argument is an integer of the drive, starting at zero.
  21. #
  22. # The CD object is not initialized, you can only call CD.get_id() and
  23. # CD.get_name() on an uninitialized drive.
  24. #
  25. # It is safe to create multiple CD objects for the same drive, they
  26. # will all cooperate normally.
  27. #
  28. self.fail()
  29. def test_get_count(self):
  30. """Ensure the correct number of CD drives can be detected."""
  31. count = pygame.cdrom.get_count()
  32. response = question('Is the correct number of CD drives on this '
  33. 'system [{}]?'.format(count))
  34. self.assertTrue(response)
  35. def test_get_init(self):
  36. """Ensure the initialization state can be retrieved."""
  37. self.assertTrue(pygame.cdrom.get_init())
  38. def test_init(self):
  39. """Ensure module still initialized after multiple init() calls."""
  40. pygame.cdrom.init()
  41. pygame.cdrom.init()
  42. self.assertTrue(pygame.cdrom.get_init())
  43. def test_quit(self):
  44. """Ensure module not initialized after quit() called."""
  45. pygame.cdrom.quit()
  46. self.assertFalse(pygame.cdrom.get_init())
  47. def test_quit__multiple(self):
  48. """Ensure module still not initialized after multiple quit() calls."""
  49. pygame.cdrom.quit()
  50. pygame.cdrom.quit()
  51. self.assertFalse(pygame.cdrom.get_init())
  52. @unittest.skipIf(0 == CD_DRIVE_COUNT, "No CD drives detected")
  53. class CDTypeTest(unittest.TestCase):
  54. @classmethod
  55. def setUpClass(cls):
  56. pygame.cdrom.init()
  57. cls._cd_id = 0 # Only testing drive 0 for now. Expand in the future.
  58. cls._cd = pygame.cdrom.CD(cls._cd_id)
  59. @classmethod
  60. def tearDownClass(cls):
  61. pygame.cdrom.quit()
  62. def setUp(self):
  63. self._cd.init()
  64. def tearDown(self):
  65. self._cd.quit()
  66. def test_eject(self):
  67. """Ensure CD drive opens/ejects."""
  68. self._cd.eject()
  69. response = question('Did the CD eject?')
  70. self.assertTrue(response)
  71. prompt("Please close the CD drive")
  72. def test_get_name(self):
  73. """Ensure correct name for CD drive."""
  74. cd_name = self._cd.get_name()
  75. response = question('Is the correct name for the CD drive [{}]?'
  76. ''.format(cd_name))
  77. self.assertTrue(response)
  78. def todo_test_get_all(self):
  79. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_all:
  80. # CD.get_all(): return [(audio, start, end, lenth), ...]
  81. # get all track information
  82. #
  83. # Return a list with information for every track on the cdrom. The
  84. # information consists of a tuple with four values. The audio value is
  85. # True if the track contains audio data. The start, end, and length
  86. # values are floating point numbers in seconds. Start and end
  87. # represent absolute times on the entire disc.
  88. #
  89. self.fail()
  90. def todo_test_get_busy(self):
  91. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_busy:
  92. # CD.get_busy(): return bool
  93. # true if the drive is playing audio
  94. #
  95. # Returns True if the drive busy playing back audio.
  96. self.fail()
  97. def todo_test_get_current(self):
  98. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_current:
  99. # CD.get_current(): return track, seconds
  100. # the current audio playback position
  101. #
  102. # Returns both the current track and time of that track. This method
  103. # works when the drive is either playing or paused.
  104. #
  105. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  106. self.fail()
  107. def test_get_empty(self):
  108. """Ensure correct name for CD drive."""
  109. prompt("Please ensure the CD drive is closed")
  110. is_empty = self._cd.get_empty()
  111. response = question('Is the CD drive empty?')
  112. self.assertEqual(is_empty, response)
  113. def test_get_id(self):
  114. """Ensure the drive id/index is correct."""
  115. cd_id = self._cd.get_id()
  116. self.assertEqual(self._cd_id, cd_id)
  117. def test_get_init(self):
  118. """Ensure the initialization state can be retrieved."""
  119. self.assertTrue(self._cd.get_init())
  120. def todo_test_get_numtracks(self):
  121. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_numtracks:
  122. # CD.get_numtracks(): return count
  123. # the number of tracks on the cdrom
  124. #
  125. # Return the number of tracks on the cdrom in the drive. This will
  126. # return zero of the drive is empty or has no tracks.
  127. #
  128. self.fail()
  129. def todo_test_get_paused(self):
  130. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_paused:
  131. # CD.get_paused(): return bool
  132. # true if the drive is paused
  133. #
  134. # Returns True if the drive is currently paused.
  135. self.fail()
  136. def todo_test_get_track_audio(self):
  137. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_track_audio:
  138. # CD.get_track_audio(track): return bool
  139. # true if the cdrom track has audio data
  140. #
  141. # Determine if a track on a cdrom contains audio data. You can also
  142. # call CD.num_tracks() and CD.get_all() to determine more information
  143. # about the cdrom.
  144. #
  145. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  146. self.fail()
  147. def todo_test_get_track_length(self):
  148. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_track_length:
  149. # CD.get_track_length(track): return seconds
  150. # length of a cdrom track
  151. #
  152. # Return a floating point value in seconds of the length of the cdrom track.
  153. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  154. self.fail()
  155. def todo_test_get_track_start(self):
  156. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.get_track_start:
  157. # CD.get_track_start(track): return seconds
  158. # start time of a cdrom track
  159. #
  160. # Return the absolute time in seconds where at start of the cdrom track.
  161. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  162. self.fail()
  163. def test_init(self):
  164. """Ensure CD drive still initialized after multiple init() calls."""
  165. self._cd.init()
  166. self._cd.init()
  167. self.assertTrue(self._cd.get_init())
  168. def todo_test_pause(self):
  169. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.pause:
  170. # CD.pause(): return None
  171. # temporarily stop audio playback
  172. #
  173. # Temporarily stop audio playback on the CD. The playback can be
  174. # resumed at the same point with the CD.resume() method. If the CD is
  175. # not playing this method does nothing.
  176. #
  177. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  178. self.fail()
  179. def todo_test_play(self):
  180. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.play:
  181. # CD.init(): return None
  182. # initialize a cdrom drive for use
  183. #
  184. # Playback audio from an audio cdrom in the drive. Besides the track
  185. # number argument, you can also pass a starting and ending time for
  186. # playback. The start and end time are in seconds, and can limit the
  187. # section of an audio track played.
  188. #
  189. # If you pass a start time but no end, the audio will play to the end
  190. # of the track. If you pass a start time and 'None' for the end time,
  191. # the audio will play to the end of the entire disc.
  192. #
  193. # See the CD.get_numtracks() and CD.get_track_audio() to find tracks to playback.
  194. # Note, track 0 is the first track on the CD. Track numbers start at zero.
  195. self.fail()
  196. def test_quit(self):
  197. """Ensure CD drive not initialized after quit() called."""
  198. self._cd.quit()
  199. self.assertFalse(self._cd.get_init())
  200. def test_quit__multiple(self):
  201. """Ensure CD drive still not initialized after multiple quit() calls.
  202. """
  203. self._cd.quit()
  204. self._cd.quit()
  205. self.assertFalse(self._cd.get_init())
  206. def todo_test_resume(self):
  207. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.resume:
  208. # CD.resume(): return None
  209. # unpause audio playback
  210. #
  211. # Unpause a paused CD. If the CD is not paused or already playing,
  212. # this method does nothing.
  213. #
  214. self.fail()
  215. def todo_test_stop(self):
  216. # __doc__ (as of 2008-08-02) for pygame.cdrom.CD.stop:
  217. # CD.stop(): return None
  218. # stop audio playback
  219. #
  220. # Stops playback of audio from the cdrom. This will also lose the
  221. # current playback position. This method does nothing if the drive
  222. # isn't already playing audio.
  223. #
  224. self.fail()
  225. ################################################################################
  226. if __name__ == '__main__':
  227. unittest.main()