Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCase : Temp directory access improvements #6204

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions python/GafferImageTest/CatalogueTest.py
Original file line number Diff line number Diff line change
@@ -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 ) :
11 changes: 7 additions & 4 deletions python/GafferTest/TestCase.py
Original file line number Diff line number Diff line change
@@ -114,11 +114,14 @@ 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 :
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 )

shutil.rmtree( self.__temporaryDirectory )

IECore.MessageHandler.setDefaultHandler( self.__defaultMessageHandler )
3 changes: 0 additions & 3 deletions python/GafferUSDTest/USDLayerWriterTest.py
Original file line number Diff line number Diff line change
@@ -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()