| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 import random | |
| 8 import unittest | |
| 9 | |
| 10 from media_test_matrix import MediaTestMatrix | |
| 11 | |
| 12 | |
| 13 class MediaTestMatrixTest(unittest.TestCase): | |
| 14 """Unit test for MediaTestMatrix class.""" | |
| 15 | |
| 16 def _ReadCSVFile(self): | |
| 17 """Reads CSV file for test and returns a media test matrix object. | |
| 18 | |
| 19 Returns: | |
| 20 a media test matrix. | |
| 21 """ | |
| 22 matrix = MediaTestMatrix() | |
| 23 # Pyauto.DataDir() method is not used to avoid dependency to pyauto. | |
| 24 data_file = os.path.join(os.pardir, os.pardir, 'data', 'media', 'csv', | |
| 25 'media_matrix_data.csv') | |
| 26 matrix.ReadData(data_file) | |
| 27 return matrix | |
| 28 | |
| 29 def testGenerateAllMediaInfosInCompactForm(self): | |
| 30 matrix = self._ReadCSVFile() | |
| 31 # Get video data only case. | |
| 32 media_test_matrix_list = matrix.GenerateAllMediaInfosInCompactForm(True) | |
| 33 self.assertEqual(len(media_test_matrix_list), 240, | |
| 34 'total number of elements in the returned list is wrong') | |
| 35 # Get all media data. | |
| 36 media_test_matrix_list = matrix.GenerateAllMediaInfosInCompactForm(False) | |
| 37 self.assertEqual(len(media_test_matrix_list), 449, | |
| 38 'total number of elements in the returned list is wrong') | |
| 39 mobile_test_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( | |
| 40 media_test_matrix_list, 'mobile0.webm') | |
| 41 self.assertEqual(mobile_test_info[2], 'mobile0.webm', | |
| 42 'the nickname of the returned element is wrong') | |
| 43 | |
| 44 def testGenerateAllMediaInfos(self): | |
| 45 matrix = self._ReadCSVFile() | |
| 46 # Get video data only case. | |
| 47 media_test_matrix_list = matrix.GenerateAllMediaInfos(True) | |
| 48 self.assertEqual(len(media_test_matrix_list), 240, | |
| 49 'total number of elements in the returned list is wrong') | |
| 50 # Get all media data. | |
| 51 media_test_matrix_list = matrix.GenerateAllMediaInfos(False) | |
| 52 self.assertEqual(len(media_test_matrix_list), 449, | |
| 53 'total number of elements in the returned list is wrong') | |
| 54 (info, url, link, tag, is_video, nickname) = ( | |
| 55 matrix.GenerateRandomMediaInfo()) | |
| 56 self.assertTrue(info is not None, | |
| 57 'randomly generated media info does not have spec') | |
| 58 self.assertTrue(url is not None, | |
| 59 'randomly generated media info does not have url') | |
| 60 self.assertTrue(link is not None, | |
| 61 'randomly generated media info does not have link') | |
| 62 self.assertTrue(tag is not None, | |
| 63 'randomly generated media info does not have tag') | |
| 64 self.assertTrue(nickname is not None, | |
| 65 'randomly generated media info does not have nickname') | |
| 66 | |
| 67 | |
| 68 if __name__ == '__main__': | |
| 69 unittest.main() | |
| OLD | NEW |