PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/external/webkit/Tools/Scripts/webkitpy/tool/bot/flakytestreporter_unittest.py

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
Python | 167 lines | 127 code | 10 blank | 30 comment | 3 complexity | 2a29a984e59f1df0bc3cb802af279cd6 MD5 | raw file
  1. # Copyright (c) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import unittest
  29. from webkitpy.common.config.committers import Committer
  30. from webkitpy.common.system.filesystem_mock import MockFileSystem
  31. from webkitpy.common.system.outputcapture import OutputCapture
  32. from webkitpy.layout_tests.layout_package import test_results
  33. from webkitpy.layout_tests.layout_package import test_failures
  34. from webkitpy.thirdparty.mock import Mock
  35. from webkitpy.tool.bot.flakytestreporter import FlakyTestReporter
  36. from webkitpy.tool.mocktool import MockTool, MockStatusServer
  37. # Creating fake CommitInfos is a pain, so we use a mock one here.
  38. class MockCommitInfo(object):
  39. def __init__(self, author_email):
  40. self._author_email = author_email
  41. def author(self):
  42. # It's definitely possible to have commits with authors who
  43. # are not in our committers.py list.
  44. if not self._author_email:
  45. return None
  46. return Committer("Mock Committer", self._author_email)
  47. class FlakyTestReporterTest(unittest.TestCase):
  48. def _mock_test_result(self, testname):
  49. return test_results.TestResult(testname, [test_failures.FailureTextMismatch()])
  50. def _assert_emails_for_test(self, emails):
  51. tool = MockTool()
  52. reporter = FlakyTestReporter(tool, 'dummy-queue')
  53. commit_infos = [MockCommitInfo(email) for email in emails]
  54. tool.checkout().recent_commit_infos_for_files = lambda paths: set(commit_infos)
  55. self.assertEqual(reporter._author_emails_for_test([]), set(emails))
  56. def test_author_emails_for_test(self):
  57. self._assert_emails_for_test([])
  58. self._assert_emails_for_test(["test1@test.com", "test1@test.com"])
  59. self._assert_emails_for_test(["test1@test.com", "test2@test.com"])
  60. def test_create_bug_for_flaky_test(self):
  61. reporter = FlakyTestReporter(MockTool(), 'dummy-queue')
  62. expected_stderr = """MOCK create_bug
  63. bug_title: Flaky Test: foo/bar.html
  64. bug_description: This is an automatically generated bug from the dummy-queue.
  65. foo/bar.html has been flaky on the dummy-queue.
  66. foo/bar.html was authored by test@test.com.
  67. http://trac.webkit.org/browser/trunk/LayoutTests/foo/bar.html
  68. FLAKE_MESSAGE
  69. The bots will update this with information from each new failure.
  70. If you believe this bug to be fixed or invalid, feel free to close. The bots will re-open if the flake re-occurs.
  71. If you would like to track this test fix with another bug, please close this bug as a duplicate. The bots will follow the duplicate chain when making future comments.
  72. component: Tools / Tests
  73. cc: test@test.com
  74. blocked: 50856
  75. """
  76. OutputCapture().assert_outputs(self, reporter._create_bug_for_flaky_test, ['foo/bar.html', ['test@test.com'], 'FLAKE_MESSAGE'], expected_stderr=expected_stderr)
  77. def test_follow_duplicate_chain(self):
  78. tool = MockTool()
  79. reporter = FlakyTestReporter(tool, 'dummy-queue')
  80. bug = tool.bugs.fetch_bug(78)
  81. self.assertEqual(reporter._follow_duplicate_chain(bug).id(), 76)
  82. def test_report_flaky_tests_creating_bug(self):
  83. tool = MockTool()
  84. tool.filesystem = MockFileSystem({"/mock/foo/bar-diffs.txt": "mock"})
  85. tool.status_server = MockStatusServer(bot_id="mock-bot-id")
  86. reporter = FlakyTestReporter(tool, 'dummy-queue')
  87. reporter._lookup_bug_for_flaky_test = lambda bug_id: None
  88. patch = tool.bugs.fetch_attachment(197)
  89. expected_stderr = """MOCK create_bug
  90. bug_title: Flaky Test: foo/bar.html
  91. bug_description: This is an automatically generated bug from the dummy-queue.
  92. foo/bar.html has been flaky on the dummy-queue.
  93. foo/bar.html was authored by abarth@webkit.org.
  94. http://trac.webkit.org/browser/trunk/LayoutTests/foo/bar.html
  95. The dummy-queue just saw foo/bar.html flake (Text diff mismatch) while processing attachment 197 on bug 42.
  96. Bot: mock-bot-id Port: MockPort Platform: MockPlatform 1.0
  97. The bots will update this with information from each new failure.
  98. If you believe this bug to be fixed or invalid, feel free to close. The bots will re-open if the flake re-occurs.
  99. If you would like to track this test fix with another bug, please close this bug as a duplicate. The bots will follow the duplicate chain when making future comments.
  100. component: Tools / Tests
  101. cc: abarth@webkit.org
  102. blocked: 50856
  103. MOCK add_attachment_to_bug: bug_id=78, description=Failure diff from mock-bot-id filename=failure.diff
  104. MOCK bug comment: bug_id=42, cc=None
  105. --- Begin comment ---
  106. The dummy-queue encountered the following flaky tests while processing attachment 197:
  107. foo/bar.html bug 78 (author: abarth@webkit.org)
  108. The dummy-queue is continuing to process your patch.
  109. --- End comment ---
  110. """
  111. test_results = [self._mock_test_result('foo/bar.html')]
  112. class MockZipFile(object):
  113. def read(self, path):
  114. return ""
  115. def namelist(self):
  116. return ['foo/bar-diffs.txt']
  117. OutputCapture().assert_outputs(self, reporter.report_flaky_tests, [patch, test_results, MockZipFile()], expected_stderr=expected_stderr)
  118. def test_optional_author_string(self):
  119. reporter = FlakyTestReporter(MockTool(), 'dummy-queue')
  120. self.assertEqual(reporter._optional_author_string([]), "")
  121. self.assertEqual(reporter._optional_author_string(["foo@bar.com"]), " (author: foo@bar.com)")
  122. self.assertEqual(reporter._optional_author_string(["a@b.com", "b@b.com"]), " (authors: a@b.com and b@b.com)")
  123. def test_results_diff_path_for_test(self):
  124. reporter = FlakyTestReporter(MockTool(), 'dummy-queue')
  125. self.assertEqual(reporter._results_diff_path_for_test("test.html"), "test-diffs.txt")
  126. def test_find_in_archive(self):
  127. reporter = FlakyTestReporter(MockTool(), 'dummy-queue')
  128. class MockZipFile(object):
  129. def namelist(self):
  130. return ["tmp/layout-test-results/foo/bar-diffs.txt"]
  131. reporter._find_in_archive("foo/bar-diffs.txt", MockZipFile())
  132. # This is not ideal, but its
  133. reporter._find_in_archive("txt", MockZipFile())