PageRenderTime 112ms CodeModel.GetById 52ms RepoModel.GetById 3ms app.codeStats 0ms

/media/tools/layout_tests/layouttest_analyzer_helpers_unittest.py

https://gitlab.com/jonnialva90/iridium-browser
Python | 212 lines | 182 code | 23 blank | 7 comment | 2 complexity | 085b7bc3ed195b77c3c492511e1d6545 MD5 | raw file
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 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. import copy
  6. from datetime import datetime
  7. import os
  8. import pickle
  9. import time
  10. import unittest
  11. import layouttest_analyzer_helpers
  12. class TestLayoutTestAnalyzerHelpers(unittest.TestCase):
  13. def testFindLatestTime(self):
  14. time_list = ['2011-08-18-19', '2011-08-18-22', '2011-08-18-21',
  15. '2012-01-11-21', '.foo']
  16. self.assertEquals(layouttest_analyzer_helpers.FindLatestTime(time_list),
  17. '2012-01-11-21')
  18. def testFindLatestTimeWithEmptyList(self):
  19. time_list = []
  20. self.assertEquals(layouttest_analyzer_helpers.FindLatestTime(time_list),
  21. None)
  22. def testFindLatestTimeWithNoValidStringInList(self):
  23. time_list = ['.foo1', '232232']
  24. self.assertEquals(layouttest_analyzer_helpers.FindLatestTime(time_list),
  25. None)
  26. def GenerateTestDataWholeAndSkip(self):
  27. """You should call this method if you want to generate test data."""
  28. file_path = os.path.join('test_data', 'base')
  29. analyzerResultMapBase = (
  30. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  31. # Remove this first part
  32. m = analyzerResultMapBase.result_map['whole']
  33. del m['media/video-source-type.html']
  34. m = analyzerResultMapBase.result_map['skip']
  35. del m['media/track/track-webvtt-tc004-magicheader.html']
  36. file_path = os.path.join('test_data', 'less')
  37. analyzerResultMapBase.Save(file_path)
  38. file_path = os.path.join('test_data', 'base')
  39. analyzerResultMapBase = AnalyzerResultMap.Load(file_path)
  40. analyzerResultMapBase.result_map['whole']['add1.html'] = True
  41. analyzerResultMapBase.result_map['skip']['add2.html'] = True
  42. file_path = os.path.join('test_data', 'more')
  43. analyzerResultMapBase.Save(file_path)
  44. def GenerateTestDataNonSkip(self):
  45. """You should call this method if you want to generate test data."""
  46. file_path = os.path.join('test_data', 'base')
  47. analyzerResultMapBase = AnalyzerResultMap.Load(file_path)
  48. m = analyzerResultMapBase.result_map['nonskip']
  49. ex = m['media/media-document-audio-repaint.html']
  50. te_info_map1 = ex['te_info'][0]
  51. te_info_map2 = copy.copy(te_info_map1)
  52. te_info_map2['NEWADDED'] = True
  53. ex['te_info'].append(te_info_map2)
  54. m = analyzerResultMapBase.result_map['nonskip']
  55. file_path = os.path.join('test_data', 'more_te_info')
  56. analyzerResultMapBase.Save(file_path)
  57. def testCompareResultMapsWholeAndSkip(self):
  58. file_path = os.path.join('test_data', 'base')
  59. analyzerResultMapBase = (
  60. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  61. file_path = os.path.join('test_data', 'less')
  62. analyzerResultMapLess = (
  63. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  64. diff = analyzerResultMapBase.CompareToOtherResultMap(analyzerResultMapLess)
  65. self.assertEquals(diff['skip'][0][0][0],
  66. 'media/track/track-webvtt-tc004-magicheader.html')
  67. self.assertEquals(diff['whole'][0][0][0],
  68. 'media/video-source-type.html')
  69. file_path = os.path.join('test_data', 'more')
  70. analyzerResultMapMore = (
  71. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  72. diff = analyzerResultMapBase.CompareToOtherResultMap(analyzerResultMapMore)
  73. self.assertEquals(diff['whole'][1][0][0], 'add1.html')
  74. self.assertEquals(diff['skip'][1][0][0], 'add2.html')
  75. def testCompareResultMapsNonSkip(self):
  76. file_path = os.path.join('test_data', 'base')
  77. analyzerResultMapBase = (
  78. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  79. file_path = os.path.join('test_data', 'more_te_info')
  80. analyzerResultMapMoreTEInfo = (
  81. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  82. m = analyzerResultMapBase.CompareToOtherResultMap(
  83. analyzerResultMapMoreTEInfo)
  84. self.assertTrue('NEWADDED' in m['nonskip'][1][0][1][0])
  85. def testGetListOfBugsForNonSkippedTests(self):
  86. file_path = os.path.join('test_data', 'base')
  87. analyzerResultMapBase = (
  88. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  89. self.assertEquals(
  90. len(analyzerResultMapBase.GetListOfBugsForNonSkippedTests().keys()),
  91. 10)
  92. def RunTestGetRevisionString(self, current_time_str, prev_time_str,
  93. expected_rev_str, expected_simple_rev_str,
  94. expected_rev_number, expected_rev_date,
  95. testname, diff_map_none=False):
  96. current_time = datetime.strptime(current_time_str, '%Y-%m-%d-%H')
  97. current_time = time.mktime(current_time.timetuple())
  98. prev_time = datetime.strptime(prev_time_str, '%Y-%m-%d-%H')
  99. prev_time = time.mktime(prev_time.timetuple())
  100. if diff_map_none:
  101. diff_map = None
  102. else:
  103. diff_map = {
  104. 'whole': [[], []],
  105. 'skip': [[(testname, 'te_info1')], []],
  106. 'nonskip': [[], []],
  107. }
  108. (rev_str, simple_rev_str, rev_number, rev_date) = (
  109. layouttest_analyzer_helpers.GetRevisionString(prev_time, current_time,
  110. diff_map))
  111. self.assertEquals(rev_str, expected_rev_str)
  112. self.assertEquals(simple_rev_str, expected_simple_rev_str)
  113. self.assertEquals(rev_number, expected_rev_number)
  114. self.assertEquals(rev_date, expected_rev_date)
  115. def testGetRevisionString(self):
  116. expected_rev_str = ('<ul><a href="http://trac.webkit.org/changeset?'
  117. 'new=94377@trunk/LayoutTests/platform/chromium/'
  118. 'test_expectations.txt&old=94366@trunk/LayoutTests/'
  119. 'platform/chromium/test_expectations.txt">94366->'
  120. '94377</a>\n'
  121. '<li>jamesr@google.com</li>\n'
  122. '<li>2011-09-01 18:00:23</li>\n'
  123. '<ul><li>-<a href="http://webkit.org/b/63878">'
  124. 'BUGWK63878</a> : <a href="http://test-results.'
  125. 'appspot.com/dashboards/flakiness_dashboard.html#'
  126. 'tests=fast/dom/dom-constructors.html">fast/dom/'
  127. 'dom-constructors.html</a> = TEXT</li>\n</ul></ul>')
  128. expected_simple_rev_str = ('<a href="http://trac.webkit.org/changeset?'
  129. 'new=94377@trunk/LayoutTests/platform/chromium/'
  130. 'test_expectations.txt&old=94366@trunk/'
  131. 'LayoutTests/platform/chromium/'
  132. 'test_expectations.txt">94366->94377</a>,')
  133. self.RunTestGetRevisionString('2011-09-02-00', '2011-09-01-00',
  134. expected_rev_str, expected_simple_rev_str,
  135. 94377, '2011-09-01 18:00:23',
  136. 'fast/dom/dom-constructors.html')
  137. def testGetRevisionStringNoneDiffMap(self):
  138. self.RunTestGetRevisionString('2011-09-02-00', '2011-09-01-00', '', '',
  139. '', '', '', diff_map_none=True)
  140. def testGetRevisionStringNoMatchingTest(self):
  141. self.RunTestGetRevisionString('2011-09-01-00', '2011-09-02-00', '', '',
  142. '', '', 'foo1.html')
  143. def testReplaceLineInFile(self):
  144. file_path = os.path.join('test_data', 'inplace.txt')
  145. f = open(file_path, 'w')
  146. f.write('Hello')
  147. f.close()
  148. layouttest_analyzer_helpers.ReplaceLineInFile(
  149. file_path, 'Hello', 'Goodbye')
  150. f = open(file_path, 'r')
  151. self.assertEquals(f.readline(), 'Goodbye')
  152. f.close()
  153. layouttest_analyzer_helpers.ReplaceLineInFile(
  154. file_path, 'Bye', 'Hello')
  155. f = open(file_path, 'r')
  156. self.assertEquals(f.readline(), 'Goodbye')
  157. f.close()
  158. def testFindLatestResultWithNoData(self):
  159. self.assertFalse(
  160. layouttest_analyzer_helpers.FindLatestResult('test_data'))
  161. def testConvertToCSVText(self):
  162. file_path = os.path.join('test_data', 'base')
  163. analyzerResultMapBase = (
  164. layouttest_analyzer_helpers.AnalyzerResultMap.Load(file_path))
  165. data, issues_txt = analyzerResultMapBase.ConvertToCSVText('11-10-10-2011')
  166. self.assertEquals(data, '11-10-10-2011,204,36,10,95')
  167. expected_issues_txt = """\
  168. BUGWK,66310,TEXT PASS,media/media-blocked-by-beforeload.html,DEBUG TEXT PASS,\
  169. media/video-source-error.html,
  170. BUGCR,86714,GPU IMAGE CRASH MAC,media/video-zoom.html,GPU IMAGE CRASH MAC,\
  171. media/video-controls-rendering.html,
  172. BUGCR,74102,GPU IMAGE PASS LINUX,media/video-controls-rendering.html,
  173. BUGWK,55718,TEXT IMAGE IMAGE+TEXT,media/media-document-audio-repaint.html,
  174. BUGCR,78376,TIMEOUT,http/tests/media/video-play-stall-seek.html,
  175. BUGCR,59415,WIN TEXT TIMEOUT PASS,media/video-loop.html,
  176. BUGCR,72223,IMAGE PASS,media/video-frame-accurate-seek.html,
  177. BUGCR,75354,TEXT IMAGE IMAGE+TEXT,media/media-document-audio-repaint.html,
  178. BUGCR,73609,TEXT,http/tests/media/video-play-stall.html,
  179. BUGWK,64003,DEBUG TEXT MAC PASS,media/video-delay-load-event.html,
  180. """
  181. self.assertEquals(issues_txt, expected_issues_txt)
  182. if __name__ == '__main__':
  183. unittest.main()