test_utils.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from StringIO import StringIO
  2. from lvc import utils
  3. import base
  4. class UtilsTest(base.Test):
  5. def test_hms_to_seconds(self):
  6. self.assertEqual(utils.hms_to_seconds(3, 2, 1),
  7. 3 * 3600 +
  8. 2 * 60 +
  9. 1)
  10. def test_hms_to_seconds_floats(self):
  11. self.assertEqual(utils.hms_to_seconds(3.0, 2.0, 1.5),
  12. 3 * 3600 +
  13. 2 * 60 +
  14. 1.5)
  15. def test_round_even(self):
  16. self.assertEqual(utils.round_even(-1), 0)
  17. self.assertEqual(utils.round_even(0), 0)
  18. self.assertEqual(utils.round_even(1), 0)
  19. self.assertEqual(utils.round_even(2), 2)
  20. self.assertEqual(utils.round_even(2.5), 2)
  21. self.assertEqual(utils.round_even(3), 2)
  22. def test_rescale_video(self):
  23. target = (1024, 768)
  24. self.assertEqual(utils.rescale_video(target, target),
  25. target)
  26. # small
  27. self.assertEqual(utils.rescale_video((512, 384), target),
  28. (512, 384))
  29. # big
  30. self.assertEqual(utils.rescale_video((2048, 1536), target),
  31. target)
  32. # widescreen
  33. self.assertEqual(utils.rescale_video((1400, 768), target,
  34. dont_upsize=False),
  35. (1024, 560))
  36. def test_line_reader(self):
  37. lines = """line1
  38. line2
  39. line3\rline4\r
  40. line5"""
  41. expected = ['line1', 'line2', 'line3', 'line4', 'line5']
  42. self.assertEqual(list(utils.line_reader(StringIO(lines))), expected)