def test_ResolveWithCache(self): testDir = os.path.abspath('testResolveWithCache/sub') if os.path.isdir(testDir): shutil.rmtree(testDir) os.makedirs(testDir) with open('testResolveWithCache/test.txt', 'w') as ofp: print('Test 1', file=ofp) with open('testResolveWithCache/sub/test.txt', 'w') as ofp: print('Test 2', file=ofp) resolver = Ar.GetResolver() # Set up a context that will search in the test root directory # first, then the subdirectory. context = Ar.DefaultResolverContext([ os.path.abspath('testResolveWithCache'), os.path.abspath('testResolveWithCache/sub')]) with Ar.ResolverContextBinder(context): with Ar.ResolverScopedCache(): # Resolve should initially find the file in the test root # directory. self.assertPathsEqual( os.path.abspath('testResolveWithCache/test.txt'), resolver.Resolve('test.txt')) os.remove('testResolveWithCache/test.txt') # After removing the file from the test root directory, # Calling Resolve again will still return the same result # as before since a scoped cache is active. self.assertPathsEqual( os.path.abspath('testResolveWithCache/test.txt'), resolver.Resolve('test.txt')) # Once the caching scope is closed, Resolve should now return # the file from the subdirectory. self.assertPathsEqual( os.path.abspath('testResolveWithCache/sub/test.txt'), resolver.Resolve('test.txt'))
parser = argparse.ArgumentParser() parser.add_argument("resolverName", type=str, help=("Name of ArResolver subclass to test")) args = parser.parse_args() SetupPlugins() Ar.SetPreferredResolver(args.resolverName) r = Ar.GetResolver() # Call each method to see whether the corresponding virtual method # on the resolver is called. # This context manager calls ArResolver::BindContext when entered # and ArResolver::UnbindContext on exit. with Ar.ResolverContextBinder(Ar.ResolverContext()): pass r.CreateDefaultContext() r.CreateDefaultContextForAsset('foo') r.CreateContextFromString('foo') r.RefreshContext(Ar.ResolverContext()) r.GetCurrentContext() r.IsContextDependentPath('foo') # This context manager calls ArResolver::BeginCacheScope when entered # and ArResolver::EndCacheScope on exit. with Ar.ResolverScopedCache(): pass