From 2d73134aec1ebb91afa805b790f89748ec607605 Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Thu, 9 Jan 2025 15:50:34 -0500 Subject: [PATCH 1/3] TestCase : Only `chmod` existing temp directory --- python/GafferTest/TestCase.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/GafferTest/TestCase.py b/python/GafferTest/TestCase.py index 9ef5ee2d15e..d86c9236b56 100644 --- a/python/GafferTest/TestCase.py +++ b/python/GafferTest/TestCase.py @@ -114,11 +114,11 @@ def tearDown( self ) : ## \todo Fix Cortex so that wrapped classes don't require garbage collection. IECore.RefCounted.collectGarbage() - for root, dirs, files in os.walk( self.temporaryDirectory() ) : - for fileName in [ p for p in files + dirs if not ( pathlib.Path( root ) / p ).is_symlink() ] : - ( pathlib.Path( root ) / fileName ).chmod( stat.S_IRWXU ) - if self.__temporaryDirectory is not None : + for root, dirs, files in os.walk( self.__temporaryDirectory ) : + for fileName in [ p for p in files + dirs if not ( pathlib.Path( root ) / p ).is_symlink() ] : + ( pathlib.Path( root ) / fileName ).chmod( stat.S_IRWXU ) + shutil.rmtree( self.__temporaryDirectory ) IECore.MessageHandler.setDefaultHandler( self.__defaultMessageHandler ) From f0575efe4b1eb9733310c6ff8d809f8a4678fcbe Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Thu, 9 Jan 2025 16:03:58 -0500 Subject: [PATCH 2/3] TestCase : Ensure temp directory can be deleted --- python/GafferTest/TestCase.py | 3 +++ python/GafferUSDTest/USDLayerWriterTest.py | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/GafferTest/TestCase.py b/python/GafferTest/TestCase.py index d86c9236b56..ad0d93261df 100644 --- a/python/GafferTest/TestCase.py +++ b/python/GafferTest/TestCase.py @@ -115,6 +115,9 @@ def tearDown( self ) : IECore.RefCounted.collectGarbage() if self.__temporaryDirectory is not None : + if os.name == "nt" : + subprocess.check_call( [ "icacls", self.__temporaryDirectory, "/grant", "Users:(OI)(CI)(W)" ] ) + for root, dirs, files in os.walk( self.__temporaryDirectory ) : for fileName in [ p for p in files + dirs if not ( pathlib.Path( root ) / p ).is_symlink() ] : ( pathlib.Path( root ) / fileName ).chmod( stat.S_IRWXU ) diff --git a/python/GafferUSDTest/USDLayerWriterTest.py b/python/GafferUSDTest/USDLayerWriterTest.py index 73a81290ff8..43eb6913a6b 100644 --- a/python/GafferUSDTest/USDLayerWriterTest.py +++ b/python/GafferUSDTest/USDLayerWriterTest.py @@ -265,8 +265,5 @@ def testNoWritePermissions( self ) : with self.assertRaisesRegex( RuntimeError, 'Failed to export layer to "{}"'.format( layerWriter["fileName"].getValue() ) ) : layerWriter["task"].execute() - if os.name == "nt" : - subprocess.check_call( [ "icacls", self.temporaryDirectory(), "/grant", "Users:(OI)(CI)(W)" ] ) - if __name__ == "__main__": unittest.main() From 394d3feb334c9fe6268ca9a9c98ed3549414feb5 Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Fri, 10 Jan 2025 11:11:47 -0500 Subject: [PATCH 3/3] CatalogueTest : Enable nonwritable test on Windows --- python/GafferImageTest/CatalogueTest.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/python/GafferImageTest/CatalogueTest.py b/python/GafferImageTest/CatalogueTest.py index 01c791d0ac2..a1059b2bda1 100644 --- a/python/GafferImageTest/CatalogueTest.py +++ b/python/GafferImageTest/CatalogueTest.py @@ -41,6 +41,7 @@ import imath import pathlib import unittest +import subprocess import IECore @@ -615,13 +616,15 @@ def testDeleteBeforeSaveCompletesWithScriptVariables( self ) : self.assertEqual( len( list( baseDirectory.glob( "*" ) ) ), 0 ) - @unittest.skipIf( os.name == "nt", "Windows allows new files in read-only directories" ) def testNonWritableDirectory( self ) : s = Gaffer.ScriptNode() s["c"] = GafferImage.Catalogue() s["c"]["directory"].setValue( self.temporaryDirectory() / "catalogue" ) - os.chmod( self.temporaryDirectory(), stat.S_IREAD ) + if os.name != "nt" : + os.chmod( self.temporaryDirectory(), stat.S_IREAD ) + else : + subprocess.check_call( [ "icacls", self.temporaryDirectory(), "/deny", "Users:(OI)(CI)(W)" ] ) r = GafferImage.ImageReader() r["fileName"].setValue( self.imagesPath() / "blurRange.exr" ) @@ -637,9 +640,17 @@ def testNonWritableDirectory( self ) : self.assertEqual( len( mh.messages ), 1 ) self.assertEqual( mh.messages[0].level, IECore.Msg.Level.Error ) - self.assertIn( "Permission denied", mh.messages[0].message ) + self.assertIn( + "Permission denied" if os.name != "nt" else "Access is denied", + mh.messages[0].message + ) - with self.assertRaisesRegex( RuntimeError, r".* : Could not open \".*\" \(Permission denied\)" ) : + with self.assertRaisesRegex( + RuntimeError, + r".* : Could not open \".*\" " + ( + "\(Permission denied\)" if os.name != "nt" else "\(No such file or directory\)" + ) + ) : GafferImage.ImageAlgo.image( s["c"]["out"] ) def testDeleteKeepsOrder( self ) :