1
# Copyright (c) 2011 Google Inc. All rights reserved.
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions are
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
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.
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.
31
from webkitpy.common.system.filesystem_mock import MockFileSystem
32
from webkitpy.common.system.outputcapture import OutputCapture
33
from webkitpy.common.net.layouttestresults import LayoutTestResults
34
from webkitpy.tool.bot.layouttestresultsreader import *
35
from webkitpy.tool.mocktool import MockTool
38
class LayoutTestResultsReaderTest(unittest.TestCase):
39
def test_missing_layout_test_results(self):
41
reader = LayoutTestResultsReader(tool, "/var/logs")
42
layout_tests_results_path = '/mock-results/full_results.json'
43
unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml'
44
tool.filesystem = MockFileSystem({layout_tests_results_path: None,
45
unit_tests_results_path: None})
46
# Make sure that our filesystem mock functions as we expect.
47
self.assertRaises(IOError, tool.filesystem.read_text_file, layout_tests_results_path)
48
self.assertRaises(IOError, tool.filesystem.read_text_file, unit_tests_results_path)
49
# layout_test_results shouldn't raise even if the results.html file is missing.
50
self.assertEqual(reader.results(), None)
52
def test_create_unit_test_results(self):
54
reader = LayoutTestResultsReader(tool, "/var/logs")
55
unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml'
56
no_failures_xml = """<?xml version="1.0" encoding="UTF-8"?>
57
<testsuites tests="3" failures="0" disabled="0" errors="0" time="11.35" name="AllTests">
58
<testsuite name="RenderTableCellDeathTest" tests="3" failures="0" disabled="0" errors="0" time="0.677">
59
<testcase name="CanSetColumn" status="run" time="0.168" classname="RenderTableCellDeathTest" />
60
<testcase name="CrashIfSettingUnsetColumnIndex" status="run" time="0.129" classname="RenderTableCellDeathTest" />
61
<testcase name="CrashIfSettingUnsetRowIndex" status="run" time="0.123" classname="RenderTableCellDeathTest" />
64
tool.filesystem = MockFileSystem({unit_tests_results_path: no_failures_xml})
65
self.assertEqual(reader._create_unit_test_results(), [])
67
def test_missing_unit_test_results_path(self):
69
tool.port().unit_tests_results_path = lambda: None
70
reader = LayoutTestResultsReader(tool, "/var/logs")
71
reader._create_layout_test_results = lambda: LayoutTestResults([])
72
# layout_test_results shouldn't raise even if the unit tests xml file is missing.
73
self.assertNotEquals(reader.results(), None)
74
self.assertEqual(reader.results().failing_tests(), [])
77
def test_layout_test_results(self):
78
reader = LayoutTestResultsReader(MockTool(), "/var/logs")
79
reader._read_file_contents = lambda path: None
80
self.assertEqual(reader.results(), None)
81
reader._read_file_contents = lambda path: ""
82
self.assertEqual(reader.results(), None)
83
reader._create_layout_test_results = lambda: LayoutTestResults([])
84
results = reader.results()
85
self.assertNotEquals(results, None)
86
self.assertEqual(results.failure_limit_count(), 30) # This value matches RunTests.NON_INTERACTIVE_FAILURE_LIMIT_COUNT
88
def test_archive_last_layout_test_results(self):
90
reader = LayoutTestResultsReader(tool, "/var/logs")
91
patch = tool.bugs.fetch_attachment(10001)
92
tool.filesystem = MockFileSystem()
93
# Should fail because the results_directory does not exist.
94
expected_logs = "/mock-results does not exist, not archiving.\n"
95
archive = OutputCapture().assert_outputs(self, reader.archive, [patch], expected_logs=expected_logs)
96
self.assertEqual(archive, None)
98
results_directory = "/mock-results"
99
# Sanity check what we assume our mock results directory is.
100
self.assertEqual(reader._results_directory(), results_directory)
101
tool.filesystem.maybe_make_directory(results_directory)
102
self.assertTrue(tool.filesystem.exists(results_directory))
104
self.assertNotEqual(reader.archive(patch), None)
105
self.assertFalse(tool.filesystem.exists(results_directory))