a70a539e88a300875eec6da566d7f7c4f05aba86
[WebKit-https.git] / Tools / Scripts / webkitpy / common / net / testoutputset_unittest.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # 1.  Redistributions of source code must retain the above copyright
9 #     notice, this list of conditions and the following disclaimer.
10 # 2.  Redistributions in binary form must reproduce the above copyright
11 #     notice, this list of conditions and the following disclaimer in the
12 #     documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25 from webkitpy.common.system.zip_mock import MockZip
26 import testoutputset
27 import unittest
28
29
30 class TestOutputSetTest(unittest.TestCase):
31     def _outputset_with_zip(self, zip, **kwargs):
32         return testoutputset.TestOutputSet('<fake-outputset>', '<fake-platform>', zip, **kwargs)
33
34     def test_text_files_get_interpreted_as_text_outputs(self):
35         zip = MockZip()
36         zip.insert('fast/dom/some-test-actual.txt', 'actual outputs')
37         b = self._outputset_with_zip(zip)
38         self.assertEquals(1, len(b.outputs_for('fast/dom/some-test')))
39         self.assertEquals('fast/dom/some-test', b.outputs_for('fast/dom/some-test.html')[0].name())
40
41     def test_image_and_checksum_files_get_interpreted_as_a_single_image_output(self):
42         zip = MockZip()
43         zip.insert('fast/dom/some-test-actual.checksum', 'abc123')
44         zip.insert('fast/dom/some-test-actual.png', '<image data>')
45         b = self._outputset_with_zip(zip)
46         outputs = b.outputs_for('fast/dom/some-test')
47         self.assertEquals(1, len(outputs))
48         output = outputs[0]
49         self.assertEquals('image', output.type())
50         self.assertEquals('abc123', output.checksum())
51
52     def test_multiple_image_outputs_are_detected(self):
53         zip = MockZip()
54         zip.insert('platform/win/fast/dom/some-test-actual.checksum', 'checksum1')
55         zip.insert('platform/win/fast/dom/some-test-actual.png', '<image data 1>')
56         zip.insert('platform/mac/fast/dom/some-test-actual.checksum', 'checksum2')
57         zip.insert('platform/mac/fast/dom/some-test-actual.png', '<image data 2>')
58         b = self._outputset_with_zip(zip)
59         outputs = b.outputs_for('fast/dom/some-test')
60         self.assertEquals(2, len(outputs))
61         self.assertFalse(outputs[0].same_content(outputs[1]))
62
63     def test_aggregate_output_set_correctly_retrieves_tests_from_multiple_output_sets(self):
64         outputset1_zip = MockZip()
65         outputset1_zip.insert('fast/dom/test-actual.txt', 'linux text output')
66         outputset1 = testoutputset.TestOutputSet('linux-outputset', 'linux', outputset1_zip)
67         outputset2_zip = MockZip()
68         outputset2_zip.insert('fast/dom/test-actual.txt', 'windows text output')
69         outputset2 = testoutputset.TestOutputSet('win-outputset', 'win', outputset2_zip)
70
71         b = testoutputset.AggregateTestOutputSet([outputset1, outputset2])
72         self.assertEquals(2, len(b.outputs_for('fast/dom/test')))
73
74     def test_can_infer_platform_from_path_if_none_provided(self):
75         zip = MockZip()
76         zip.insert('platform/win/some-test-expected.png', '<image data>')
77         zip.insert('platform/win/some-test-expected.checksum', 'abc123')
78         b = testoutputset.TestOutputSet('local LayoutTests outputset', None, zip)
79
80         outputs = b.outputs_for('some-test')
81         self.assertEquals(1, len(outputs))
82         self.assertEquals('win', outputs[0].platform())
83
84     def test_test_extension_is_ignored(self):
85         zip = MockZip()
86         zip.insert('test/test-a-actual.txt', 'actual outputs')
87         b = self._outputset_with_zip(zip)
88         outputs = b.outputs_for('test/test-a.html')
89         self.assertEquals(1, len(outputs))
90         self.assertEquals('test/test-a', outputs[0].name())
91
92     def test_existing_outputs_are_marked_as_such(self):
93         zip = MockZip()
94         zip.insert('test/test-a-expected.txt', 'expected outputs')
95         b = self._outputset_with_zip(zip)
96         outputs = b.outputs_for('test/test-a.html')
97         self.assertEquals(1, len(outputs))
98         self.assertFalse(outputs[0].is_actual())
99
100     def test_only_returns_outputs_of_specified_type(self):
101         zip = MockZip()
102         zip.insert('test/test-a-expected.txt', 'expected outputs')
103         zip.insert('test/test-a-expected.checksum', 'expected outputs')
104         zip.insert('test/test-a-expected.png', 'expected outputs')
105         b = self._outputset_with_zip(zip)
106
107         outputs = b.outputs_for('test/test-a.html')
108         text_outputs = b.outputs_for('test/test-a.html', target_type='text')
109         image_outputs = b.outputs_for('test/test-a.html', target_type='image')
110
111         self.assertEquals(2, len(outputs))
112         self.assertEquals(1, len(text_outputs))
113         self.assertEquals(1, len(image_outputs))
114         self.assertEquals('text', text_outputs[0].type())
115         self.assertEquals('image', image_outputs[0].type())
116
117     def test_exclude_expected_outputs_works(self):
118         zip = MockZip()
119         zip.insert('test-expected.txt',  'expected outputs stored on server for some reason')
120         b = self._outputset_with_zip(zip, include_expected=False)
121         outputs = b.outputs_for('test', target_type=None)
122         self.assertEquals(0, len(outputs))
123
124 if __name__ == "__main__":
125     unittest.main()