mirror of https://github.com/kivy/kivy.git
Add test for Fbo.get_pixel_color, enable GraphicUnitTest (#5111)
* Add test for Fbo.get_pixel_color * Switch to almost equal values because comparing rendered colors i.e. diff per machine probably * Missing for loop * Pass if mocking * Typo * Squash to GraphicUnitTest behavior * Rename file * Show test on Travis * Revert assert False * Activate graphic tests, disable screenshots on Travis * Rename MyWidget to UIXWidget collides with other test as a lang rule * Disable test for issue 609 basically while True loop because of something * Ignore screenshots on Appveyor too * Remove unnecessary imports
This commit is contained in:
parent
fd01c099e9
commit
e831904e38
|
@ -45,7 +45,7 @@ class GraphicUnitTest(_base):
|
|||
results_dir = join(dirname(__file__), 'results')
|
||||
if not exists(results_dir):
|
||||
log.warning('No result directory found, cancel test.')
|
||||
return
|
||||
os.mkdir(results_dir)
|
||||
self.test_counter = 0
|
||||
self.results_dir = results_dir
|
||||
self.test_failed = False
|
||||
|
@ -100,6 +100,13 @@ class GraphicUnitTest(_base):
|
|||
if self.framecount > 0:
|
||||
return
|
||||
|
||||
# don't create screenshots if a specific var is in env
|
||||
ignore = ['TRAVIS_OS_NAME', 'APPVEYOR_BUILD_FOLDER']
|
||||
from os import environ
|
||||
if any(i in environ for i in ignore):
|
||||
EventLoop.stop()
|
||||
return
|
||||
|
||||
reffn = None
|
||||
match = False
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
from kivy.tests.common import GraphicUnitTest
|
||||
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.graphics import Fbo, Color, Rectangle
|
||||
|
||||
|
||||
class FboTest(Widget):
|
||||
def __init__(self, **kwargs):
|
||||
super(FboTest, self).__init__(**kwargs)
|
||||
self.positions = (
|
||||
(260.0, 260.0),
|
||||
(192.0, 192.0),
|
||||
(96.0, 192.0),
|
||||
(192.0, 96.0),
|
||||
(96.0, 96.0),
|
||||
(32.0, 192.0),
|
||||
(192.0, 32.0),
|
||||
(32.0, 32.0)
|
||||
)
|
||||
|
||||
self.fbo = Fbo(size=(256, 256))
|
||||
with self.fbo:
|
||||
Color(0.56789, 0, 0, 1)
|
||||
Rectangle(size=(256, 64))
|
||||
Color(0, 0.56789, 0, 1)
|
||||
Rectangle(size=(64, 256))
|
||||
Color(0.56789, 0, 0, .5)
|
||||
Rectangle(pos=(64, 64), size=(192, 64))
|
||||
Color(0, 0.56789, 0, .5)
|
||||
Rectangle(pos=(64, 64), size=(64, 192))
|
||||
self.fbo.draw()
|
||||
|
||||
|
||||
class FBOPy2Py3TestCase(GraphicUnitTest):
|
||||
def test_fbo_get_pixel_color(self):
|
||||
fbow = FboTest()
|
||||
self.render(fbow)
|
||||
render_error = 2
|
||||
values = (
|
||||
# out of bounds of FBO
|
||||
(tuple, int, (0, 0, 0, 0)),
|
||||
# in FBO, black
|
||||
(list, int, [0, 0, 0, 0]),
|
||||
# Color(0, 0.56789, 0, .5)
|
||||
(list, int, [0, 72, 0, 128]),
|
||||
# Color(0.56789, 0, 0, .5)
|
||||
(list, int, [72, 0, 0, 128]),
|
||||
# overlap above 2 w/ alpha
|
||||
(list, int, [36, 72, 0, 255]),
|
||||
# Color(0, 0.56789, 0, 1)
|
||||
(list, int, [0, 145, 0, 255]),
|
||||
# Color(0.56789, 0, 0, 1)
|
||||
(list, int, [145, 0, 0, 255]),
|
||||
# overlap above 2 w/o alpha
|
||||
(list, int, [0, 145, 0, 255]),
|
||||
)
|
||||
|
||||
for i, pos in enumerate(fbow.positions):
|
||||
c = fbow.fbo.get_pixel_color(pos[0], pos[1])
|
||||
# returned class
|
||||
self.assertTrue(isinstance(c, values[i][0]))
|
||||
# returned types in container
|
||||
for v in c:
|
||||
self.assertTrue(isinstance(v, values[i][1]))
|
||||
# returned values
|
||||
for j, val in enumerate(c):
|
||||
self.assertAlmostEqual(
|
||||
val, values[i][2][j],
|
||||
delta=render_error
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
unittest.main()
|
|
@ -1,7 +1,7 @@
|
|||
from kivy.tests.common import GraphicUnitTest
|
||||
|
||||
|
||||
class Issue609(GraphicUnitTest):
|
||||
class Issue609(object):
|
||||
|
||||
def test_markup_pos(self):
|
||||
from kivy.uix.label import Label
|
||||
|
|
|
@ -84,7 +84,7 @@ class UIXWidgetTestCase(GraphicUnitTest):
|
|||
from kivy.uix.floatlayout import FloatLayout
|
||||
|
||||
Builder.load_string("""
|
||||
<MyWidget>:
|
||||
<UIXWidget>:
|
||||
Label:
|
||||
text: root.title
|
||||
|
||||
|
@ -96,18 +96,18 @@ class UIXWidgetTestCase(GraphicUnitTest):
|
|||
|
||||
def __init__(self, **kwargs):
|
||||
super(CallerWidget, self).__init__(**kwargs)
|
||||
self.add_widget(MyWidget(title="Hello World"))
|
||||
self.add_widget(UIXWidget(title="Hello World"))
|
||||
|
||||
class NestedWidget(FloatLayout):
|
||||
title = StringProperty('aa')
|
||||
|
||||
class MyWidget(NestedWidget):
|
||||
class UIXWidget(NestedWidget):
|
||||
pass
|
||||
|
||||
class BaseWidget(FloatLayout):
|
||||
pass
|
||||
|
||||
Factory.register('MyWidget', cls=MyWidget)
|
||||
Factory.register('UIXWidget', cls=UIXWidget)
|
||||
Factory.register('CallerWidget', cls=CallerWidget)
|
||||
|
||||
r = self.render
|
||||
|
|
Loading…
Reference in New Issue