datafiles.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Default Device Conversion Parameters
  2. import os
  3. class TestData(object):
  4. _UNITTESTFILES = os.path.abspath(
  5. os.path.join(
  6. os.path.dirname(
  7. os.path.abspath(
  8. __file__)), "..", "..", "..", 'testdata'))
  9. _SIKTESTFILES = os.path.abspath(
  10. os.path.join(
  11. os.path.dirname(
  12. os.path.abspath(__file__)), 'testdata'))
  13. _FILES = {
  14. 'mp3-0.mp3':
  15. {
  16. 'testdir': _UNITTESTFILES,
  17. 'container': 'mp3',
  18. 'audio_codec': 'mp3',
  19. 'title': 'Invisible Walls',
  20. 'artist': 'Revolution Void',
  21. 'album': 'Increase The Dosage',
  22. 'track': '1',
  23. 'genre': 'Blues',
  24. 'duration': 1.07
  25. },
  26. 'mp3-1.mp3':
  27. {
  28. 'testdir': _UNITTESTFILES,
  29. 'container': 'mp3',
  30. 'audio_codec': 'mp3',
  31. 'title': 'Race Lieu',
  32. 'artist': 'Ckz',
  33. 'album': 'The Heart EP',
  34. 'track': '2/5',
  35. 'duration': 1.07
  36. },
  37. 'mp3-2.mp3':
  38. {
  39. 'testdir': _UNITTESTFILES,
  40. 'container': 'mp3',
  41. 'audio_codec': 'mp3',
  42. 'artist': 'This American Life',
  43. 'genre': 'Podcast',
  44. 'title': '#426: Tough Room 2011',
  45. 'duration': 1.09
  46. },
  47. 'theora_with_ogg_extension.ogg':
  48. {
  49. 'testdir': _UNITTESTFILES,
  50. 'container': 'ogg',
  51. 'video_codec': 'theora',
  52. 'width': 320,
  53. 'height': 240,
  54. 'duration': 0.1
  55. },
  56. 'webm-0.webm':
  57. {
  58. 'testdir': _UNITTESTFILES,
  59. 'container': ['matroska', 'webm'],
  60. 'video_codec': 'vp8',
  61. 'width': 1920,
  62. 'height': 912,
  63. 'duration': 0.43
  64. },
  65. 'mp4-0.mp4':
  66. {
  67. 'testdir': _UNITTESTFILES,
  68. 'container': ['mov',
  69. 'mp4',
  70. 'm4a',
  71. '3gp',
  72. '3g2',
  73. 'mj2',
  74. 'isom',
  75. 'mp41'],
  76. 'video_codec': 'h264',
  77. 'audio_codec': 'aac',
  78. 'width': 640,
  79. 'height': 480,
  80. 'title': 'Africa: Cash for Climate Change?',
  81. 'duration': 312.37
  82. },
  83. 'nuls.mp3':
  84. {
  85. 'testdir': _UNITTESTFILES,
  86. 'container': 'mp3',
  87. 'title': 'Invisible'
  88. },
  89. 'drm.m4v':
  90. {
  91. 'testdir': _UNITTESTFILES,
  92. 'container': ['mov',
  93. 'mp4',
  94. 'm4a',
  95. '3gp',
  96. '3g2',
  97. 'mj2',
  98. 'M4V',
  99. 'mp42',
  100. 'isom'],
  101. 'video_codec': 'none',
  102. 'audio_codec': 'aac',
  103. 'has_drm': ['audio', 'video'],
  104. 'width': 640,
  105. 'height': 480,
  106. 'title': 'Thinkers',
  107. 'artist': 'The Most Extreme',
  108. 'album': 'The Most Extreme',
  109. 'track': '10',
  110. 'genre': 'Nonfiction',
  111. 'duration': 2668.8
  112. },
  113. 'baby_block.m4v':
  114. {
  115. 'testdir': _SIKTESTFILES,
  116. 'container': 'm4v',
  117. 'video_codec': 'h264',
  118. 'audio_codec': 'aac',
  119. 'width': 960,
  120. 'height': 540,
  121. },
  122. # this is a fake mp4 file it is a pdf file renamed to an mp4
  123. # extension and should fail conversion
  124. 'fake_video.mp4':
  125. {
  126. 'testdir': _SIKTESTFILES,
  127. 'container': 'mp4',
  128. 'video_codec': None,
  129. 'audio_codec': None,
  130. 'width': None,
  131. 'height': None,
  132. },
  133. 'story_stuff.mov':
  134. {
  135. 'testdir': _SIKTESTFILES,
  136. 'container': 'mov',
  137. 'video_codec': 'h264',
  138. 'audio_codec': 'mp3',
  139. 'width': 320,
  140. 'height': 180,
  141. }
  142. }
  143. def testfile_attr(self, testfile, default):
  144. try:
  145. return self._FILES[testfile][default]
  146. except:
  147. return None
  148. def directory_list(self, testdir):
  149. files_list = []
  150. for k, v in self._FILES.iteritems():
  151. if 'testdir' in v and testdir in v['testdir']:
  152. files_list.append(k)
  153. return files_list
  154. def test_data(self, many=True, new=False):
  155. """Grab a subset of the test files.
  156. Default selection is to use the unittest files,
  157. but, if I need extra files, getting them from
  158. the sikuli test files dir.
  159. """
  160. DEFAULT_UNITTESTFILES = ['mp4-0.mp4', 'webm-0.webm']
  161. DEFAULT_SIKTESTFILES = ['baby_block.m4v', 'story_styff.mov']
  162. if new:
  163. TESTFILES = DEFAULT_SIKTESTFILES
  164. else:
  165. TESTFILES = DEFAULT_UNITTESTFILES
  166. DATADIR = self.testfile_attr(TESTFILES[0], 'testdir')
  167. if not many:
  168. TESTFILES = TESTFILES[:1]
  169. print(TESTFILES)
  170. return DATADIR, TESTFILES