From e28e1587d7041b62f820822eba7baadb581cb513 Mon Sep 17 00:00:00 2001 From: ivanimanishi Date: Tue, 5 Nov 2024 17:23:42 -0800 Subject: [PATCH] test/IECoreGL : Relax precisions for image comparisons --- Changes | 1 + test/IECoreGL/Camera.py | 16 ++++++++-------- test/IECoreGL/ImmediateRenderer.py | 18 +++++++++--------- test/IECoreGL/MeshPrimitiveTest.py | 24 ++++++++++++------------ test/IECoreGL/Renderer.py | 22 +++++++++++----------- test/IECoreGL/ShadingTest.py | 3 ++- 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/Changes b/Changes index 4247a2eefc..18564d6106 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,7 @@ Build - CI : - IECoreHoudini tests updated to pass on newer environments. + - IECoreGL tests updated with relaxed precisions for image comparisons. 10.5.10.0 (relative to 10.5.9.5) ========= diff --git a/test/IECoreGL/Camera.py b/test/IECoreGL/Camera.py index 9840160f62..8476a25b25 100644 --- a/test/IECoreGL/Camera.py +++ b/test/IECoreGL/Camera.py @@ -64,7 +64,7 @@ def testPositioning( self ) : i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() dimensions = i.dataWindow.size() + imath.V2i( 1 ) midpoint = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertEqual( i["G"][midpoint], 0 ) + self.assertAlmostEqual( i["G"][midpoint], 0, 6 ) # render a plane at z = 0 with the camera moved back a touch to see it r = IECoreGL.Renderer() @@ -87,7 +87,7 @@ def testPositioning( self ) : i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() dimensions = i.dataWindow.size() + imath.V2i( 1 ) midpoint = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertEqual( i["A"][midpoint], 1 ) + self.assertAlmostEqual( i["A"][midpoint], 1, 6 ) def testXYOrientation( self ) : @@ -113,15 +113,15 @@ def testXYOrientation( self ) : i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() dimensions = i.dataWindow.size() + imath.V2i( 1 ) index = dimensions.x * dimensions.y//2 + dimensions.x - 1 - self.assertEqual( i["A"][index], 1 ) + self.assertAlmostEqual( i["A"][index], 1, 6 ) self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x//2 - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 0 ) + self.assertAlmostEqual( i["A"][index], 1, 6 ) + self.assertAlmostEqual( i["R"][index], 0, 6 ) self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) def setUp( self ) : diff --git a/test/IECoreGL/ImmediateRenderer.py b/test/IECoreGL/ImmediateRenderer.py index d381690d28..d97acac24b 100644 --- a/test/IECoreGL/ImmediateRenderer.py +++ b/test/IECoreGL/ImmediateRenderer.py @@ -76,20 +76,20 @@ def test( self ) : i = IECore.Reader.create( outputFileName ).read() dimensions = i.dataWindow.size() + imath.V2i( 1 ) index = int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) + self.assertAlmostEqual( i["A"][index], 1, 6 ) self.assertAlmostEqual( i["R"][index], 1, 6 ) self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 0 ) - self.assertEqual( i["G"][index], 0 ) + self.assertAlmostEqual( i["A"][index], 1, 6 ) + self.assertAlmostEqual( i["R"][index], 0, 6 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) self.assertAlmostEqual( i["B"][index], 1, 6 ) index = 0 - self.assertEqual( i["A"][index], 0 ) - self.assertEqual( i["R"][index], 0 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["A"][index], 0, 6 ) + self.assertAlmostEqual( i["R"][index], 0, 6 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) def setUp( self ) : diff --git a/test/IECoreGL/MeshPrimitiveTest.py b/test/IECoreGL/MeshPrimitiveTest.py index 7fdd3f6eea..4e4aad7546 100644 --- a/test/IECoreGL/MeshPrimitiveTest.py +++ b/test/IECoreGL/MeshPrimitiveTest.py @@ -158,13 +158,13 @@ def testUniformCs( self ) : dimensions = image.dataWindow.size() + imath.V2i( 1 ) index = dimensions.x * int(dimensions.y * 0.75) + int(dimensions.x * 0.25) self.assertAlmostEqual( image["R"][index], 1, 6 ) - self.assertEqual( image["G"][index], 0 ) - self.assertEqual( image["B"][index], 0 ) + self.assertAlmostEqual( image["G"][index], 0, 6 ) + self.assertAlmostEqual( image["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.75) + int(dimensions.x * 0.75) - self.assertEqual( image["R"][index], 0 ) + self.assertAlmostEqual( image["R"][index], 0, 6 ) self.assertAlmostEqual( image["G"][index], 1, 6 ) - self.assertEqual( image["B"][index], 0 ) + self.assertAlmostEqual( image["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.25) + int(dimensions.x * 0.75) self.assertAlmostEqual( image["R"][index], 1, 6 ) @@ -172,8 +172,8 @@ def testUniformCs( self ) : self.assertAlmostEqual( image["B"][index], 1, 6 ) index = dimensions.x * int(dimensions.y * 0.25) + int(dimensions.x * 0.25) - self.assertEqual( image["R"][index], 0 ) - self.assertEqual( image["G"][index], 0 ) + self.assertAlmostEqual( image["R"][index], 0, 6 ) + self.assertAlmostEqual( image["G"][index], 0, 6 ) self.assertAlmostEqual( image["B"][index], 1, 6 ) def testBound( self ) : @@ -192,10 +192,10 @@ def testFaceNormals( self ) : #include "IECoreGL/FragmentShader.h" IECOREGL_FRAGMENTSHADER_IN vec3 fragmentN; - void main() - { - gl_FragColor = vec4( fragmentN, 1.0 ); - } + void main() + { + gl_FragColor = vec4( fragmentN, 1.0 ); + } """ r = IECoreGL.Renderer() @@ -224,8 +224,8 @@ def testFaceNormals( self ) : image = IECore.Reader.create( self.outputFileName ).read() dimensions = image.dataWindow.size() + imath.V2i( 1 ) index = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertEqual( image["R"][index], 0 ) - self.assertEqual( image["G"][index], 0 ) + self.assertAlmostEqual( image["R"][index], 0, 6 ) + self.assertAlmostEqual( image["G"][index], 0, 6 ) self.assertAlmostEqual( image["B"][index], 1, 6 ) def testIndexedUV( self ) : diff --git a/test/IECoreGL/Renderer.py b/test/IECoreGL/Renderer.py index e977c2f879..effdd751ca 100644 --- a/test/IECoreGL/Renderer.py +++ b/test/IECoreGL/Renderer.py @@ -282,17 +282,17 @@ def testStackBug( self ) : index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) self.assertAlmostEqual( i["R"][index], 1, 6 ) self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.5) self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 1) - 1 self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) def testPrimVars( self ) : @@ -345,18 +345,18 @@ def testPrimVars( self ) : i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testPrimVars.tif" ) ).read() dimensions = i.dataWindow.size() + imath.V2i( 1 ) index = dimensions.x * int(dimensions.y * 0.5) - self.assertEqual( i["R"][index], 0 ) + self.assertAlmostEqual( i["R"][index], 0, 6 ) self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) + self.assertAlmostEqual( i["B"][index], 0, 6 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 1) - 1 - self.assertEqual( i["R"][index], 0 ) - self.assertEqual( i["G"][index], 0 ) + self.assertAlmostEqual( i["R"][index], 0, 6 ) + self.assertAlmostEqual( i["G"][index], 0, 6 ) self.assertAlmostEqual( i["B"][index], 1, 6 ) ## \todo Make this assert something diff --git a/test/IECoreGL/ShadingTest.py b/test/IECoreGL/ShadingTest.py index 0720e2fb1a..9cffe9f290 100644 --- a/test/IECoreGL/ShadingTest.py +++ b/test/IECoreGL/ShadingTest.py @@ -825,10 +825,11 @@ def testVertexCsDoesntAffectWireframe( self ) : # wireframe is green, and vertex Cs is black, # so there should be no contribution from # wireframe or solid shading in the red channel. - self.assertEqual( sum( image["R"] ), 0 ) + self.assertAlmostEqual( sum( image["R"] ), 0, 4 ) # black vertex colour should have no effect on # green wireframe, so we should have some wireframe # contribution in the green channel. + self.assertNotAlmostEqual( sum( image["G"] ), 0, 4 ) self.assertTrue( sum( image["G"] ) > 0 ) def testUniformFloatArrayParameters( self ) :