test_conversions.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. import tempfile
  5. import shutil
  6. import unittest
  7. import lvc
  8. from lvcgui import MVCGui
  9. import datafiles
  10. import devices
  11. data = datafiles.TestData()
  12. class Test_Conversions(unittest.TestCase):
  13. """For any completed conversion
  14. I want to be able to locate and play the file
  15. And it should be formatted as I have specified
  16. """
  17. def setUp(self):
  18. """
  19. Each tests assumes that I there are files in the list ready
  20. to be converted to some format.
  21. """
  22. self.lvc = MVCGui()
  23. self.lvc.lvc_focus()
  24. print("starting test: ", self.shortDescription())
  25. datadir, testfiles = data.test_data(many=True)
  26. self.lvc.browse_for_files(datadir, testfiles)
  27. self.output_dir = tempfile.mkdtemp()
  28. self.lvc.choose_save_location(self.output_dir)
  29. def test_send_file_to_itunes(self):
  30. """Scenario: Send to iTunes.
  31. Given I have "Send to iTunes" checked
  32. When I convert the an apple format
  33. Then the file is added to my iTunes library
  34. """
  35. item = "mp4-0.mp4"
  36. lvc = MVCGui()
  37. lvc.choose_device_conversion("iPad")
  38. lvc.choose_itunes()
  39. lvc.start_conversions()
  40. lvc.verify_completed(item, 30)
  41. assert lvc.verify_itunes(item)
  42. def test_verify_custom_output_directory(self):
  43. """Scenario: File in specific output location.
  44. Given I have set the output directory to "directory"
  45. When I convert a file
  46. Then the output file is in the specified directory
  47. """
  48. custom_output_dir = os.path.join(os.getenv("HOME"), "Desktop")
  49. item = "mp4-0.mp4"
  50. lvc.lvcGui()
  51. lvc.choose_device_conversion("KindleFire")
  52. lvc.choose_save_location(custom_output_dir)
  53. lvc.start_conversions()
  54. lvc.verify_completed(item, 30)
  55. assert lvc.verify_output_dir(self, item, custom_output_dir)
  56. def test_file_in_default_location(self):
  57. """Scenario: File in default output location.
  58. Given I have set the output directory to "default"
  59. When I convert a file
  60. Then the output file is in the default directory
  61. """
  62. datadir, testfile = data.test_data()
  63. item = testfile[0]
  64. lvc.lvcGui()
  65. lvc.choose_device_conversion("Galaxy Tab")
  66. lvc.choose_save_location('default')
  67. lvc.start_conversions()
  68. lvc.verify_completed(item, 30)
  69. assert lvc.verify_output_dir(self, item, datadir)
  70. def test_output_file_name_in_default_dir(self):
  71. """Scenario: Output file name when saved in default (same) directory.
  72. When I convert a file
  73. Then it is named with the file name (or even better item title)
  74. As the base and the output container is the extension
  75. """
  76. self.fail('I do not know the planned naming convention yet')
  77. def test_output_file_name_in_custom_dir(self):
  78. """Scenario: Output file name when saved in default (same) directory.
  79. When I convert a file
  80. Then it is named with the file name (or even better item title)
  81. As the base and the output container is the extension
  82. """
  83. self.fail('I do not know the planned naminig convention yet')
  84. def test_output_video_no_upsize(self):
  85. datadir, testfile = data.test_data()
  86. # mp4-0.mp4 is smaller than the Apple Universal Setting
  87. item = testfile[0]
  88. lvc.lvcGui()
  89. lvc.choose_device_conversion("Apple Universal")
  90. lvc.choose_dont_upsize('on')
  91. lvc.start_conversion()
  92. assert lvc.verify_size(os.path.join(
  93. datadir, item), width, height)
  94. """Scenario: Output file video size.
  95. When I convert a file to "format"
  96. And Don't Upsize is selected
  97. Then the output file dimensions are not changed if the input file
  98. is smaller than the device
  99. """
  100. # This test is best covered more completely in unittests
  101. # to verify that we resize according to device sizes
  102. # mp4-0.mp4 is smaller than the Apple Universal Setting
  103. item = "mp4-0.mp4"
  104. lvc.lvcGui()
  105. lvc.choose_device_conversion("Apple Universal")
  106. lvc.choose_dont_upsize('on')
  107. lvc.start_conversion()
  108. assert lvc.verify_size(os.path.join(
  109. self.output_dir, item), width, height)
  110. def test_output_video_upsize(self):
  111. """Scenario: Output file video size.
  112. When I convert a file to "format"
  113. And Don't Upsize is NOT selected
  114. The the output file dimensions are changed to match the device spec.
  115. """
  116. # This test is best covered more completely in unittests
  117. # to verify that we resize according to device sizes
  118. # mp4-0.mp4 is smaller than the Apple Universal Setting
  119. item = "mp4-0.mp4"
  120. lvc.lvcGui()
  121. lvc.choose_device_conversion("Apple Universal")
  122. lvc.choose_dont_upsize('off')
  123. lvc.start_conversion()
  124. assert lvc.verify_size(os.path.join(
  125. self.output_dir, item), width, height)
  126. def test_completed_conversions_display(self):
  127. """Scenario: File displays as completed.
  128. When I convert a file
  129. Then the file displays as completed
  130. """
  131. item = "mp4-0.mp4"
  132. lvc.lvcGui()
  133. lvc.choose_device_conversion("Xoom")
  134. lvc.choose_save_location(custom_output_dir)
  135. lvc.start_conversions()
  136. assert lvc.verify_completed(item, 30)
  137. def test_failed_conversion_display(self):
  138. """Scenario: File fails conversion.
  139. When I convert a "file" to "format"
  140. And the file conversion fails
  141. Then the file displays as failed.
  142. """
  143. item = 'fake_video.mp4'
  144. item_dir = data.testfile_attr(item, 'testdir')
  145. lvc.lvcGui()
  146. lvc.browse_for_files(item_dir, item)
  147. lvc.choose_device_conversion("iPhone")
  148. lvc.start_conversion()
  149. assert lvc.verify_failed(item)
  150. def test_ffmpeg_log_output_on_failure(self):
  151. """Scenario: Show ffmpeg output.
  152. Given I convert a file
  153. When I view the ffmpeg output
  154. Then the ffmpeg output is displayed in a text window
  155. """
  156. item = 'fake_video.mp4'
  157. item_dir = data.testfile_attr(item, 'testdir')
  158. lvc.lvcGui()
  159. lvc.browse_for_files(item_dir, item)
  160. lvc.choose_device_conversion("iPhone")
  161. lvc.start_conversion()
  162. lvc.verify_failed(item)
  163. assert lvc.show_ffmpeg_output(item)
  164. def tearDown(self):
  165. shutil.rmtree(self.output_dir)
  166. self.lvc_quit()