2 ##########################################################################
4 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sub license, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice (including the
16 # next paragraph) shall be included in all copies or substantial portions
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 # IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 ##########################################################################
30 """Base classes for tests.
32 Loosely inspired on Python's unittest module.
39 # Enumerate all pixel formats
41 for name
, value
in globals().items():
42 if name
.startswith("PIPE_FORMAT_") and isinstance(value
, int):
46 def make_image(width
, height
, rgba
):
52 outpixels
= outimage
.load()
53 for y
in range(0, height
):
54 for x
in range(0, width
):
55 offset
= (y
*width
+ x
)*4
56 r
, g
, b
, a
= [int(min(max(rgba
[offset
+ ch
], 0.0), 1.0)*255) for ch
in range(4)]
57 outpixels
[x
, y
] = r
, g
, b
60 def save_image(width
, height
, rgba
, filename
):
61 outimage
= make_image(width
, height
, rgba
)
62 outimage
.save(filename
, "PNG")
64 def show_image(width
, height
, **rgbas
):
66 from PIL
import Image
, ImageTk
75 for i
in range(len(labels
)):
77 outimage
= make_image(width
, height
, rgbas
[label
])
80 window
= tk
.Toplevel(root
)
84 image1
= ImageTk
.PhotoImage(outimage
)
87 window
.geometry("%dx%d+%d+%d" % (w
, h
, x
, y
))
88 panel1
= tk
.Label(window
, image
=image1
)
89 panel1
.pack(side
='top', fill
='both', expand
='yes')
96 class TestFailure(Exception):
100 class TestSkip(Exception):
110 def _run(self
, result
):
111 raise NotImplementedError
114 result
= TestResult()
119 class TestCase(Test
):
121 def __init__(self
, dev
, **kargs
):
124 self
.__dict
__.update(kargs
)
126 def description(self
):
127 raise NotImplementedError
130 raise NotImplementedError
132 def _run(self
, result
):
133 result
.test_start(self
)
136 except KeyboardInterrupt:
139 result
.test_skipped(self
)
141 result
.test_failed(self
)
143 result
.test_passed(self
)
146 class TestSuite(Test
):
148 def __init__(self
, tests
= None):
155 def add_test(self
, test
):
156 self
.tests
.append(test
)
158 def _run(self
, result
):
159 for test
in self
.tests
:
170 self
.failed_descriptions
= []
172 def test_start(self
, test
):
174 print "Running %s..." % test
.description()
176 def test_passed(self
, test
):
180 def test_skipped(self
, test
):
184 def test_failed(self
, test
):
186 self
.failed_descriptions
.append(test
.description())
190 print "%u tests, %u passed, %u skipped, %u failed" % (self
.tests
, self
.passed
, self
.skipped
, self
.failed
)
191 for description
in self
.failed_descriptions
:
192 print " %s" % description