<s> from __future__ import with_statement <EOL> import unittest <EOL> import time <EOL> import datetime <EOL> import pwd <EOL> import grp <EOL> import os <EOL> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> class FileSystemPathTest ( GafferTest . TestCase ) : <EOL> def test ( self ) : <EOL> p = Gaffer . FileSystemPath ( __file__ ) <EOL> self . assert_ ( p . isValid ( ) ) <EOL> self . assert_ ( p . isLeaf ( ) ) <EOL> while len ( p ) : <EOL> del p [ - <NUM_LIT:1> ] <EOL> self . assert_ ( p . isValid ( ) ) <EOL> self . assert_ ( not p . isLeaf ( ) ) <EOL> def testIsLeaf ( self ) : <EOL> path = Gaffer . FileSystemPath ( "<STR_LIT>" ) <EOL> self . assert_ ( not path . isLeaf ( ) ) <EOL> def testConstructWithFilter ( self ) : <EOL> p = Gaffer . FileSystemPath ( __file__ ) <EOL> self . failUnless ( p . getFilter ( ) is None ) <EOL> f = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> p = Gaffer . FileSystemPath ( __file__ , filter = f ) <EOL> self . failUnless ( p . getFilter ( ) . isSame ( f ) ) <EOL> def testBrokenSymbolicLinks ( self ) : <EOL> os . symlink ( self . temporaryDirectory ( ) + "<STR_LIT>" , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> d = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> c = d . children ( ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:1> ) <EOL> l = c [ <NUM_LIT:0> ] <EOL> self . assertEqual ( str ( l ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( l . isValid ( ) , True ) <EOL> info = l . info ( ) <EOL> self . failUnless ( info is not None ) <EOL> def testSymLinkInfo ( self ) : <EOL> with open ( self . temporaryDirectory ( ) + "<STR_LIT>" , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> os . symlink ( self . temporaryDirectory ( ) + "<STR_LIT>" , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> a = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> l = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> aInfo = a . info ( ) <EOL> self . assertEqual ( aInfo [ "<STR_LIT>" ] , l . info ( ) [ "<STR_LIT>" ] ) <EOL> os . remove ( str ( a ) ) <EOL> self . assertNotEqual ( aInfo [ "<STR_LIT>" ] , l . info ( ) [ "<STR_LIT>" ] ) <EOL> def testCopy ( self ) : <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> p2 = p . copy ( ) <EOL> self . assertEqual ( p , p2 ) <EOL> self . assertEqual ( str ( p ) , str ( p2 ) ) <EOL> def testEmptyPath ( self ) : <EOL> p = Gaffer . FileSystemPath ( ) <EOL> self . assertEqual ( str ( p ) , "<STR_LIT>" ) <EOL> self . assertTrue ( p . isEmpty ( ) ) <EOL> self . assertFalse ( p . isValid ( ) ) <EOL> def testRelativePath ( self ) : <EOL> os . chdir ( self . temporaryDirectory ( ) ) <EOL> with open ( self . temporaryDirectory ( ) + "<STR_LIT>" , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> p = Gaffer . FileSystemPath ( "<STR_LIT:a>" ) <EOL> self . assertEqual ( str ( p ) , "<STR_LIT:a>" ) <EOL> self . assertFalse ( p . isEmpty ( ) ) <EOL> self . assertTrue ( p . isValid ( ) ) <EOL> p2 = Gaffer . FileSystemPath ( "<STR_LIT>" ) <EOL> self . assertEqual ( str ( p2 ) , "<STR_LIT>" ) <EOL> self . assertFalse ( p2 . isEmpty ( ) ) <EOL> self . assertFalse ( p2 . isValid ( ) ) <EOL> def testRelativePathChildren ( self ) : <EOL> os . chdir ( self . temporaryDirectory ( ) ) <EOL> os . mkdir ( "<STR_LIT>" ) <EOL> with open ( self . temporaryDirectory ( ) + "<STR_LIT>" , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> p = Gaffer . FileSystemPath ( "<STR_LIT>" ) <EOL> c = p . children ( ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( str ( c [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) <EOL> self . assertTrue ( c [ <NUM_LIT:0> ] . isValid ( ) ) <EOL> def testChildrenOfFile ( self ) : <EOL> p = Gaffer . FileSystemPath ( __file__ ) <EOL> self . assertEqual ( p . children ( ) , [ ] ) <EOL> def testModificationTimes ( self ) : <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> p . append ( "<STR_LIT:t>" ) <EOL> with open ( str ( p ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> mt = p . property ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( mt , datetime . datetime ) ) <EOL> self . assertLess ( ( datetime . datetime . utcnow ( ) - mt ) . total_seconds ( ) , <NUM_LIT:2> ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> with open ( str ( p ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> mt = p . property ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( mt , datetime . datetime ) ) <EOL> self . assertLess ( ( datetime . datetime . utcnow ( ) - mt ) . total_seconds ( ) , <NUM_LIT:2> ) <EOL> def testOwner ( self ) : <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> p . append ( "<STR_LIT:t>" ) <EOL> with open ( str ( p ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> o = p . property ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( o , str ) ) <EOL> self . assertEqual ( o , pwd . getpwuid ( os . stat ( str ( p ) ) . st_uid ) . pw_name ) <EOL> def testGroup ( self ) : <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> p . append ( "<STR_LIT:t>" ) <EOL> with open ( str ( p ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> g = p . property ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( g , str ) ) <EOL> self . assertEqual ( g , grp . getgrgid ( os . stat ( str ( p ) ) . st_gid ) . gr_name ) <EOL> def testPropertyNames ( self ) : <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) ) <EOL> a = p . propertyNames ( ) <EOL> self . assertTrue ( isinstance ( a , list ) ) <EOL> self . assertTrue ( "<STR_LIT>" in a ) <EOL> self . assertTrue ( "<STR_LIT>" in a ) <EOL> self . assertTrue ( "<STR_LIT>" in a ) <EOL> self . assertTrue ( "<STR_LIT>" in a ) <EOL> self . assertTrue ( "<STR_LIT>" not in a ) <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) , includeSequences = True ) <EOL> self . assertTrue ( "<STR_LIT>" in p . propertyNames ( ) ) <EOL> def testSequences ( self ) : <EOL> os . mkdir ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> for n in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> with open ( self . temporaryDirectory ( ) + "<STR_LIT:/>" + n , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) , includeSequences = True ) <EOL> self . assertTrue ( p . getIncludeSequences ( ) ) <EOL> c = p . children ( ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:8> ) <EOL> s = sorted ( c , key = str ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:0> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:1> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:2> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:3> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:4> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:5> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:6> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:7> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> for x in s : <EOL> self . assertTrue ( x . isValid ( ) ) <EOL> if not os . path . isdir ( str ( x ) ) : <EOL> self . assertTrue ( x . isLeaf ( ) ) <EOL> self . assertEqual ( x . property ( "<STR_LIT>" ) , pwd . getpwuid ( os . stat ( str ( p ) ) . st_uid ) . pw_name ) <EOL> self . assertEqual ( x . property ( "<STR_LIT>" ) , grp . getgrgid ( os . stat ( str ( p ) ) . st_gid ) . gr_name ) <EOL> self . assertLess ( ( datetime . datetime . utcnow ( ) - x . property ( "<STR_LIT>" ) ) . total_seconds ( ) , <NUM_LIT:2> ) <EOL> if "<STR_LIT>" not in str ( x ) : <EOL> self . assertFalse ( x . isFileSequence ( ) ) <EOL> self . assertEqual ( x . fileSequence ( ) , None ) <EOL> self . assertEqual ( x . property ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> if os . path . isdir ( str ( x ) ) : <EOL> self . assertEqual ( x . property ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> else : <EOL> self . assertEqual ( x . property ( "<STR_LIT>" ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( s [ <NUM_LIT:0> ] . property ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertTrue ( s [ <NUM_LIT:0> ] . isFileSequence ( ) ) <EOL> self . assertTrue ( isinstance ( s [ <NUM_LIT:0> ] . fileSequence ( ) , IECore . FileSequence ) ) <EOL> self . assertEqual ( s [ <NUM_LIT:0> ] . fileSequence ( ) , IECore . FileSequence ( str ( s [ <NUM_LIT:0> ] ) , IECore . frameListFromList ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ] ) ) ) <EOL> self . assertEqual ( s [ <NUM_LIT:0> ] . property ( "<STR_LIT>" ) , <NUM_LIT:4> * <NUM_LIT:3> ) <EOL> self . assertEqual ( s [ <NUM_LIT:4> ] . property ( "<STR_LIT>" ) , "<STR_LIT:3>" ) <EOL> self . assertTrue ( s [ <NUM_LIT:4> ] . isFileSequence ( ) ) <EOL> self . assertTrue ( isinstance ( s [ <NUM_LIT:4> ] . fileSequence ( ) , IECore . FileSequence ) ) <EOL> self . assertEqual ( s [ <NUM_LIT:4> ] . fileSequence ( ) , IECore . FileSequence ( str ( s [ <NUM_LIT:4> ] ) , IECore . frameListFromList ( [ <NUM_LIT:3> ] ) ) ) <EOL> self . assertEqual ( s [ <NUM_LIT:4> ] . property ( "<STR_LIT>" ) , <NUM_LIT:4> ) <EOL> p2 = p . copy ( ) <EOL> self . assertTrue ( p2 . getIncludeSequences ( ) ) <EOL> self . assertEqual ( len ( p2 . children ( ) ) , <NUM_LIT:8> ) <EOL> p = Gaffer . FileSystemPath ( self . temporaryDirectory ( ) , includeSequences = False ) <EOL> self . assertFalse ( p . getIncludeSequences ( ) ) <EOL> c = p . children ( ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:6> ) <EOL> s = sorted ( c , key = str ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:0> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:1> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:2> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:3> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:4> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> self . assertEqual ( str ( s [ <NUM_LIT:5> ] ) , self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> p . setIncludeSequences ( True ) <EOL> self . assertTrue ( p . getIncludeSequences ( ) ) <EOL> c = p . children ( ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:8> ) <EOL> def setUp ( self ) : <EOL> GafferTest . TestCase . setUp ( self ) <EOL> self . __originalCWD = os . getcwd ( ) <EOL> def tearDown ( self ) : <EOL> GafferTest . TestCase . tearDown ( self ) <EOL> os . chdir ( self . __originalCWD ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
