Skip to content

Commit

Permalink
useAScript
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Nov 15, 2023
1 parent 49ec1d2 commit 574ce52
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions python/GafferImageTest/CatalogueTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import imath
import pathlib
import unittest
import sys

import IECore

Expand Down Expand Up @@ -1011,54 +1010,46 @@ 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
# are closed before the first `Display::imageReceivedSignal()` is
# 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.
Expand Down

0 comments on commit 574ce52

Please sign in to comment.