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