fix the spelling in whole piglit
[piglit.git] / unittests / framework / backends / test_json_update.py
blob06950ef97878210152c8bf02138342592e867d5c
1 # coding=utf-8
2 # Copyright (c) 2014-2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Tests for JSON backend version updates."""
24 import os
25 try:
26 import simplejson as json
27 except ImportError:
28 import json
29 try:
30 import mock
31 except ImportError:
32 from unittest import mock
34 import jsonschema
35 import pytest
37 from framework import backends
39 # pylint: disable=protected-access,no-self-use
42 @pytest.fixture(autouse=True, scope='module')
43 def setup_module():
44 with mock.patch.dict(backends.json.compression.os.environ,
45 {'PIGLIT_COMPRESSION': 'none'}):
46 yield
49 class TestV7toV8(object):
50 """Tests for Version 7 to version 8."""
52 data = {
53 "results_version": 7,
54 "name": "test",
55 "options": {
56 "profile": ['quick'],
57 "dmesg": False,
58 "verbose": False,
59 "platform": "gbm",
60 "sync": False,
61 "valgrind": False,
62 "filter": [],
63 "concurrent": "all",
64 "test_count": 0,
65 "exclude_tests": [],
66 "exclude_filter": [],
67 "env": {},
69 "lspci": "stuff",
70 "uname": "more stuff",
71 "glxinfo": "and stuff",
72 "wglinfo": "stuff",
73 "clinfo": "stuff",
74 "tests": {
75 'a@test': {
76 'time': 1.2,
77 'dmesg': '',
78 'result': 'fail',
79 '__type__': 'TestResult',
80 'command': '/a/command',
81 'traceback': None,
82 'out': '',
83 'environment': 'A=variable',
84 'returncode': 0,
85 'err': '',
86 'pid': 5,
87 'subtests': {
88 '__type__': 'Subtests',
90 'exception': None,
93 "time_elapsed": 1.2,
94 '__type__': 'TestrunResult',
97 @pytest.fixture
98 def result(self, tmpdir):
99 p = tmpdir.join('result.json')
100 p.write(json.dumps(self.data, default=backends.json.piglit_encoder))
101 with p.open('r') as f:
102 return backends.json._update_seven_to_eight(backends.json._load(f))
104 def test_time(self, result):
105 """backends.json.update_results (7 -> 8): test time is stored as start
106 and end.
108 assert result['tests']['a@test']['time']['start'] == 0.0
109 assert result['tests']['a@test']['time']['end'] == 1.2
111 def test_time_elapsed(self, result):
112 """backends.json.update_results (7 -> 8): total time is stored as start
113 and end.
115 assert result['time_elapsed']['start'] == 0.0
116 assert result['time_elapsed']['end'] == 1.2
118 def test_valid(self, result):
119 with open(os.path.join(os.path.dirname(__file__), 'schema',
120 'piglit-8.json'),
121 'r') as f:
122 schema = json.load(f)
123 jsonschema.validate(
124 json.loads(json.dumps(result, default=backends.json.piglit_encoder)),
125 schema)
128 class TestV8toV9(object):
129 """Tests for Version 8 to version 9."""
131 data = {
132 "results_version": 8,
133 "name": "test",
134 "options": {
135 "profile": ['quick'],
136 "dmesg": False,
137 "verbose": False,
138 "platform": "gbm",
139 "sync": False,
140 "valgrind": False,
141 "filter": [],
142 "concurrent": "all",
143 "test_count": 0,
144 "exclude_tests": [],
145 "exclude_filter": [],
146 "env": {},
148 "lspci": "stuff",
149 "uname": "more stuff",
150 "glxinfo": "and stuff",
151 "wglinfo": "stuff",
152 "clinfo": "stuff",
153 "tests": {
154 'a@test': {
155 "time": {
156 'start': 1.2,
157 'end': 1.8,
158 '__type__': 'TimeAttribute'
160 'dmesg': '',
161 'result': 'fail',
162 '__type__': 'TestResult',
163 'command': '/a/command',
164 'traceback': None,
165 'out': '',
166 'environment': 'A=variable',
167 'returncode': 0,
168 'err': '',
169 'pid': 5,
170 'subtests': {
171 '__type__': 'Subtests',
173 'exception': None,
175 'b@test': {
176 "time": {
177 'start': 1.2,
178 'end': 1.8,
179 '__type__': 'TimeAttribute'
181 'dmesg': '',
182 'result': 'fail',
183 '__type__': 'TestResult',
184 'command': '/a/command',
185 'traceback': None,
186 'out': '',
187 'environment': 'A=variable',
188 'returncode': 0,
189 'err': '',
190 'subtests': {
191 '__type__': 'Subtests',
193 'exception': None,
196 "time_elapsed": {
197 'start': 1.2,
198 'end': 1.8,
199 '__type__': 'TimeAttribute'
201 '__type__': 'TestrunResult',
204 @pytest.fixture
205 def result(self, tmpdir):
206 p = tmpdir.join('result.json')
207 p.write(json.dumps(self.data, default=backends.json.piglit_encoder))
208 with p.open('r') as f:
209 return backends.json._update_eight_to_nine(backends.json._load(f))
211 def test_pid(self, result):
212 assert result['tests']['a@test']['pid'] == [5]
214 def test_no_pid(self, result):
215 assert result['tests']['b@test']['pid'] == []
217 def test_valid(self, result):
218 with open(os.path.join(os.path.dirname(__file__), 'schema',
219 'piglit-9.json'),
220 'r') as f:
221 schema = json.load(f)
222 jsonschema.validate(
223 json.loads(json.dumps(result, default=backends.json.piglit_encoder)),
224 schema)
227 class TestV9toV10(object):
228 """Tests for Version 8 to version 9."""
230 data = {
231 "results_version": 9,
232 "name": "test",
233 "options": {
234 "profile": ['quick'],
235 "dmesg": False,
236 "verbose": False,
237 "platform": "gbm",
238 "sync": False,
239 "valgrind": False,
240 "filter": [],
241 "concurrent": "all",
242 "test_count": 0,
243 "exclude_tests": [],
244 "exclude_filter": [],
245 "env": {},
247 "lspci": "stuff",
248 "uname": "more stuff",
249 "glxinfo": "and stuff",
250 "wglinfo": "stuff",
251 "clinfo": "stuff",
252 "tests": {
253 'a@test': {
254 "time": {
255 'start': 1.2,
256 'end': 1.8,
257 '__type__': 'TimeAttribute'
259 'dmesg': '',
260 'result': 'fail',
261 '__type__': 'TestResult',
262 'command': '/a/command',
263 'traceback': None,
264 'out': '',
265 'environment': 'A=variable',
266 'returncode': 0,
267 'err': '',
268 'pid': [5],
269 'subtests': {
270 '__type__': 'Subtests',
272 'exception': None,
275 "time_elapsed": {
276 'start': 1.2,
277 'end': 1.8,
278 '__type__': 'TimeAttribute'
280 '__type__': 'TestrunResult',
283 @pytest.fixture
284 def result(self, tmpdir):
285 p = tmpdir.join('result.json')
286 p.write(json.dumps(self.data, default=backends.json.piglit_encoder))
287 with p.open('r') as f:
288 return backends.json._update_nine_to_ten(backends.json._load(f))
290 @pytest.mark.parametrize("key", ['glxinfo', 'wglinfo', 'clinfo', 'uname', 'lspci'])
291 def test(self, key, result):
292 assert key not in result, 'Root key/value not removed'
293 assert key in result['info']['system'], 'Key not added to info/system'
294 assert result['info']['system'][key] == self.data[key], \
295 'Value not set properly.'
297 def test_valid(self, result):
298 with open(os.path.join(os.path.dirname(__file__), 'schema',
299 'piglit-10.json'),
300 'r') as f:
301 schema = json.load(f)
302 jsonschema.validate(
303 json.loads(json.dumps(result, default=backends.json.piglit_encoder)),
304 schema)