From 574ce523f62e3e61a300bf7c5fbafb26e571edfd Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 15 Nov 2023 13:00:16 +0000 Subject: [PATCH] useAScript --- python/GafferImageTest/CatalogueTest.py | 35 +++++++++---------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/python/GafferImageTest/CatalogueTest.py b/python/GafferImageTest/CatalogueTest.py index 28851d19a90..d793390b767 100644 --- a/python/GafferImageTest/CatalogueTest.py +++ b/python/GafferImageTest/CatalogueTest.py @@ -41,7 +41,6 @@ import imath import pathlib import unittest -import sys import IECore @@ -1011,32 +1010,27 @@ def testYouOnlySaveOnce( self ) : # Send a bunch of AOVs to a Catalogue image, but don't # close the drivers yet. - catalogue = GafferImage.Catalogue() - print( "TEMPORARY DIRECTORY IS", self.temporaryDirectory() ) - print( "CATALOGUE DIRECTORY IS", self.temporaryDirectory() / "catalogue" ) - catalogue["directory"].setValue( self.temporaryDirectory() / "catalogue" ) - print( "PLUG VALUE IS", catalogue["directory"].getValue() ) + script = Gaffer.ScriptNode() - constant = GafferImage.Constant() - constant["format"].setValue( GafferImage.Format( 100, 100 ) ) - constant["color"].setValue( imath.Color4f( 1, 0, 0, 1 ) ) + script["catalogue"] = GafferImage.Catalogue() + script["catalogue"]["directory"].setValue( self.temporaryDirectory() / "catalogue" ) + + script["constant"] = GafferImage.Constant() + script["constant"]["format"].setValue( GafferImage.Format( 100, 100 ) ) + script["constant"]["color"].setValue( imath.Color4f( 1, 0, 0, 1 ) ) - sys.stderr.write( "OPENING DRIVERS\n" ) drivers = [] for layer in [ "" ] + [ f"aov{n}" for n in range( 0, 10 ) ] : - constant["layer"].setValue( layer ) - drivers.append( self.sendImage( constant["out"], catalogue, waitForSave = False, close = False ) ) + script["constant"]["layer"].setValue( layer ) + drivers.append( self.sendImage( script["constant"]["out"], script["catalogue"], waitForSave = False, close = False ) ) - sys.stderr.write( "FINISHED OPENING DRIVERS\n" ) - - self.assertEqual( len( catalogue["images"] ), 1 ) + self.assertEqual( len( script["catalogue"]["images"] ), 1 ) # Now close the drivers from a background thread, as they will be by a # real renderer, and check that the image is saved to file appropriately. with GafferTest.ParallelAlgoTest.UIThreadCallHandler() as handler : - sys.stderr.write( "Starting closing thread\n" ) closingThread = threading.Thread( target = lambda : [ d.close( withCallHandler = False ) for d in drivers ] ) closingThread.start() # In practice, renderers close drivers fast enough that all drivers @@ -1044,21 +1038,18 @@ def testYouOnlySaveOnce( self ) : # emitted on the UI thread. Emulate this by waiting for the thread to # finish before calling `assertCalled()` closingThread.join() - sys.stderr.write( "Joined closing thread\n" ) # We now have a bunch of pending UI thread calls, one for each driver, # so handle those. We expect the first call to start the saving process, # but that process happens in the background and won't be visible yet. for driver in drivers : handler.assertCalled() - self.assertEqual( catalogue["images"][0]["fileName"].getValue(), "" ) - sys.stderr.write( "Done assertCalled for drivers\n" ) + self.assertEqual( script["catalogue"]["images"][0]["fileName"].getValue(), "" ) # The saving process will make one more UI thread call, to make the # result of the save visible. Handle that and check we now have an image # file. - sys.stderr.write( "fileName " + catalogue["images"][0]["fileName"].getValue() + "\n" ) handler.assertCalled() - self.assertNotEqual( catalogue["images"][0]["fileName"].getValue(), "" ) - self.assertTrue( pathlib.Path( catalogue["images"][0]["fileName"].getValue() ).is_file() ) + self.assertNotEqual( script["catalogue"]["images"][0]["fileName"].getValue(), "" ) + self.assertTrue( pathlib.Path( script["catalogue"]["images"][0]["fileName"].getValue() ).is_file() ) # That should be it. There should definitely not be a whole load more # attempts to save the image, so assert that no more UI thread calls are # made.