OLD | NEW |
| (Empty) |
1 # Copyright (c) 2011 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 | |
29 import unittest2 as unittest | |
30 | |
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.common.host_mock import MockHost | |
35 | |
36 from .layouttestresultsreader import LayoutTestResultsReader | |
37 | |
38 | |
39 class LayoutTestResultsReaderTest(unittest.TestCase): | |
40 def test_missing_layout_test_results(self): | |
41 host = MockHost() | |
42 reader = LayoutTestResultsReader(host, "/mock-results", "/var/logs") | |
43 layout_tests_results_path = '/mock-results/full_results.json' | |
44 unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml' | |
45 host.filesystem = MockFileSystem({layout_tests_results_path: None, | |
46 unit_tests_results_path: None}) | |
47 # Make sure that our filesystem mock functions as we expect. | |
48 self.assertRaises(IOError, host.filesystem.read_text_file, layout_tests_
results_path) | |
49 self.assertRaises(IOError, host.filesystem.read_text_file, unit_tests_re
sults_path) | |
50 # layout_test_results shouldn't raise even if the results.json file is m
issing. | |
51 self.assertIsNone(reader.results()) | |
52 | |
53 def test_create_unit_test_results(self): | |
54 host = MockHost() | |
55 reader = LayoutTestResultsReader(host, "/mock-results", "/var/logs") | |
56 unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml' | |
57 no_failures_xml = """<?xml version="1.0" encoding="UTF-8"?> | |
58 <testsuites tests="3" failures="0" disabled="0" errors="0" time="11.35" name="Al
lTests"> | |
59 <testsuite name="RenderTableCellDeathTest" tests="3" failures="0" disabled="0"
errors="0" time="0.677"> | |
60 <testcase name="CanSetColumn" status="run" time="0.168" classname="RenderTab
leCellDeathTest" /> | |
61 <testcase name="CrashIfSettingUnsetColumnIndex" status="run" time="0.129" cl
assname="RenderTableCellDeathTest" /> | |
62 <testcase name="CrashIfSettingUnsetRowIndex" status="run" time="0.123" class
name="RenderTableCellDeathTest" /> | |
63 </testsuite> | |
64 </testsuites>""" | |
65 host.filesystem = MockFileSystem({unit_tests_results_path: no_failures_x
ml}) | |
66 self.assertEqual(reader._create_unit_test_results(), []) | |
67 | |
68 def test_missing_unit_test_results_path(self): | |
69 host = MockHost() | |
70 reader = LayoutTestResultsReader(host, "/mock-results", "/var/logs") | |
71 reader._create_layout_test_results = lambda: LayoutTestResults([]) | |
72 reader._create_unit_test_results = lambda: None | |
73 # layout_test_results shouldn't raise even if the unit tests xml file is
missing. | |
74 self.assertIsNotNone(reader.results(), None) | |
75 self.assertEqual(reader.results().failing_tests(), []) | |
76 | |
77 | |
78 def test_layout_test_results(self): | |
79 reader = LayoutTestResultsReader(MockHost(), "/mock-results", "/var/logs
") | |
80 reader._read_file_contents = lambda path: None | |
81 self.assertIsNone(reader.results()) | |
82 reader._read_file_contents = lambda path: "" | |
83 self.assertIsNone(reader.results()) | |
84 reader._create_layout_test_results = lambda: LayoutTestResults([]) | |
85 results = reader.results() | |
86 self.assertIsNotNone(results) | |
87 self.assertEqual(results.failure_limit_count(), 30) # This value matche
s RunTests.NON_INTERACTIVE_FAILURE_LIMIT_COUNT | |
88 | |
89 def test_archive_last_layout_test_results(self): | |
90 host = MockHost() | |
91 results_directory = "/mock-results" | |
92 reader = LayoutTestResultsReader(host, results_directory, "/var/logs") | |
93 patch = host.bugs.fetch_attachment(10001) | |
94 host.filesystem = MockFileSystem() | |
95 # Should fail because the results_directory does not exist. | |
96 expected_logs = "/mock-results does not exist, not archiving.\n" | |
97 archive = OutputCapture().assert_outputs(self, reader.archive, [patch],
expected_logs=expected_logs) | |
98 self.assertIsNone(archive) | |
99 | |
100 host.filesystem.maybe_make_directory(results_directory) | |
101 self.assertTrue(host.filesystem.exists(results_directory)) | |
102 | |
103 self.assertIsNotNone(reader.archive(patch)) | |
104 self.assertFalse(host.filesystem.exists(results_directory)) | |
105 | |
106 def test_archive_last_layout_test_results_with_relative_path(self): | |
107 host = MockHost() | |
108 results_directory = "/mock-checkout/layout-test-results" | |
109 | |
110 host.filesystem.maybe_make_directory(results_directory) | |
111 host.filesystem.maybe_make_directory('/var/logs') | |
112 self.assertTrue(host.filesystem.exists(results_directory)) | |
113 | |
114 host.filesystem.chdir('/var') | |
115 reader = LayoutTestResultsReader(host, results_directory, 'logs') | |
116 patch = host.bugs.fetch_attachment(10001) | |
117 # Should fail because the results_directory does not exist. | |
118 self.assertIsNotNone(reader.archive(patch)) | |
119 self.assertEqual(host.workspace.source_path, results_directory) | |
120 self.assertEqual(host.workspace.zip_path, '/var/logs/50000-layout-test-r
esults.zip') | |
OLD | NEW |