diff tests/test-filecache.py @ 20045:b3684fd2ff1a

scmutil.filecache: support watching over multiple files
author Siddharth Agarwal <sid0@fb.com>
date Sat, 16 Nov 2013 13:29:39 -0800
parents 42deff43460a
children ce26928cbe41
line wrap: on
line diff
--- a/tests/test-filecache.py	Sat Nov 16 13:24:26 2013 -0800
+++ b/tests/test-filecache.py	Sat Nov 16 13:29:39 2013 -0800
@@ -18,7 +18,7 @@
     def sjoin(self, p):
         return p
 
-    @filecache('x')
+    @filecache('x', 'y')
     def cached(self):
         print 'creating'
         return 'string from function'
@@ -31,12 +31,12 @@
                 pass
 
 def basic(repo):
-    print "* file doesn't exist"
+    print "* neither file exists"
     # calls function
     repo.cached
 
     repo.invalidate()
-    print "* file still doesn't exist"
+    print "* neither file still exists"
     # uses cache
     repo.cached
 
@@ -57,7 +57,7 @@
     repo.cached
 
     repo.invalidate()
-    print "* nothing changed with file x"
+    print "* nothing changed with either file"
     # stats file again, reuses object
     repo.cached
 
@@ -72,6 +72,41 @@
     print "* file x changed inode"
     repo.cached
 
+    # create empty file y
+    f = open('y', 'w')
+    f.close()
+    repo.invalidate()
+    print "* empty file y created"
+    # should recreate the object
+    repo.cached
+
+    f = open('y', 'w')
+    f.write('A')
+    f.close()
+    repo.invalidate()
+    print "* file y changed size"
+    # should recreate the object
+    repo.cached
+
+    f = scmutil.opener('.')('y', 'w', atomictemp=True)
+    f.write('B')
+    f.close()
+
+    repo.invalidate()
+    print "* file y changed inode"
+    repo.cached
+
+    f = scmutil.opener('.')('x', 'w', atomictemp=True)
+    f.write('c')
+    f.close()
+    f = scmutil.opener('.')('y', 'w', atomictemp=True)
+    f.write('C')
+    f.close()
+
+    repo.invalidate()
+    print "* both files changed inode"
+    repo.cached
+
 def fakeuncacheable():
     def wrapcacheable(orig, *args, **kwargs):
         return False
@@ -83,10 +118,11 @@
     origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable',
                                             wrapcacheable)
 
-    try:
-        os.remove('x')
-    except OSError:
-        pass
+    for fn in ['x', 'y']:
+        try:
+            os.remove(fn)
+        except OSError:
+            pass
 
     basic(fakerepo())
 
@@ -110,9 +146,10 @@
 
 def setbeforeget(repo):
     os.remove('x')
+    os.remove('y')
     repo.cached = 'string set externally'
     repo.invalidate()
-    print "* file x doesn't exist"
+    print "* neither file exists"
     print repo.cached
     repo.invalidate()
     f = open('x', 'w')
@@ -121,6 +158,18 @@
     print "* file x created"
     print repo.cached
 
+    repo.cached = 'string 2 set externally'
+    repo.invalidate()
+    print "* string set externally again"
+    print repo.cached
+
+    repo.invalidate()
+    f = open('y', 'w')
+    f.write('b')
+    f.close()
+    print "* file y created"
+    print repo.cached
+
 print 'basic:'
 print
 basic(fakerepo())