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 29import unittest 30 31from webkitpy.common.net.buildbot import Build 32from webkitpy.common.net.failuremap import * 33from webkitpy.common.net.regressionwindow import RegressionWindow 34from webkitpy.tool.mocktool import MockBuilder 35 36 37class FailureMapTest(unittest.TestCase): 38 builder1 = MockBuilder("Builder1") 39 builder2 = MockBuilder("Builder2") 40 41 build1a = Build(builder1, build_number=22, revision=1233, is_green=True) 42 build1b = Build(builder1, build_number=23, revision=1234, is_green=False) 43 build2a = Build(builder2, build_number=89, revision=1233, is_green=True) 44 build2b = Build(builder2, build_number=90, revision=1235, is_green=False) 45 46 regression_window1 = RegressionWindow(build1a, build1b, failing_tests=[u'test1', u'test1']) 47 regression_window2 = RegressionWindow(build2a, build2b, failing_tests=[u'test1']) 48 49 def _make_failure_map(self): 50 failure_map = FailureMap() 51 failure_map.add_regression_window(self.builder1, self.regression_window1) 52 failure_map.add_regression_window(self.builder2, self.regression_window2) 53 return failure_map 54 55 def test_failing_revisions(self): 56 failure_map = self._make_failure_map() 57 self.assertEquals(failure_map.failing_revisions(), [1234, 1235]) 58 59 def test_new_failures(self): 60 failure_map = self._make_failure_map() 61 failure_map.filter_out_old_failures(lambda revision: False) 62 self.assertEquals(failure_map.failing_revisions(), [1234, 1235]) 63 64 def test_new_failures_with_old_revisions(self): 65 failure_map = self._make_failure_map() 66 failure_map.filter_out_old_failures(lambda revision: revision == 1234) 67 self.assertEquals(failure_map.failing_revisions(), []) 68 69 def test_new_failures_with_more_old_revisions(self): 70 failure_map = self._make_failure_map() 71 failure_map.filter_out_old_failures(lambda revision: revision == 1235) 72 self.assertEquals(failure_map.failing_revisions(), [1234]) 73 74 def test_tests_failing_for(self): 75 failure_map = self._make_failure_map() 76 self.assertEquals(failure_map.tests_failing_for(1234), [u'test1']) 77