Rev 1248: Add some tests for the LogCache. in http://people.samba.org/bzr/jelmer/bzr-svn/svn-1.5
Jelmer Vernooij
jelmer at samba.org
Mon Jun 23 21:10:25 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/svn-1.5
------------------------------------------------------------
revno: 1248
revision-id: jelmer at samba.org-20080623201024-h4sqj4yorq0et2po
parent: jelmer at samba.org-20080623194502-0pvdon0hl71y6w8v
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: svn-1.5
timestamp: Mon 2008-06-23 22:10:24 +0200
message:
Add some tests for the LogCache.
modified:
logwalker.py logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
tests/test_logwalker.py test_logwalker.py-20060622141944-pkocc3rj8g62ukbi-1
=== modified file 'logwalker.py'
--- a/logwalker.py 2008-06-23 16:20:08 +0000
+++ b/logwalker.py 2008-06-23 20:10:24 +0000
@@ -172,10 +172,16 @@
def get_revision_paths(self, revnum):
"""Return all history information for a given revision number"""
- return self.cachedb.execute("""
+ result = self.cachedb.execute("""
SELECT path, action, copyfrom_path, copyfrom_rev
FROM changed_path WHERE rev=?
""", (revnum,))
+ paths = {}
+ for p, act, cf, cr in result:
+ if cf is not None:
+ cf = cf.encode("utf-8")
+ paths[p.encode("utf-8")] = (act, cf, cr)
+ return paths
def changes_path(self, path, revnum):
if path == '':
@@ -191,8 +197,9 @@
AND (path=? OR path GLOB (? || '/*'))
""", (revnum, path, path)).fetchone()[0] > 0
- def insert_path(self, rev, path, action, copyfrom_path, copyfrom_rev):
+ def insert_path(self, rev, path, action, copyfrom_path=None, copyfrom_rev=-1):
"""Insert new history information into the cache."""
+ assert action in ("A", "R", "D", "M")
self.cachedb.execute("""
REPLACE INTO changed_path
(rev, path, action, copyfrom_path, copyfrom_rev)
@@ -201,9 +208,13 @@
self._commit_conditionally()
def get_revprops(self, revnum):
- return self.cachedb.execute("""
+ result = self.cachedb.execute("""
SELECT name, value FROM revprop WHERE rev = ?
""", (revnum,))
+ revprops = {}
+ for k,v in result:
+ revprops[k.encode("utf-8")] = v.encode("utf-8")
+ return revprops
def insert_revprop(self, rev, name, value):
self.cachedb.execute("""
@@ -578,14 +589,7 @@
if revnum == 0:
return {'': ('A', None, -1)}
- result = self.cache.get_revision_paths(revnum)
-
- paths = {}
- for p, act, cf, cr in result:
- if cf is not None:
- cf = cf.encode("utf-8")
- paths[p.encode("utf-8")] = (act, cf, cr)
- return paths
+ return self.cache.get_revision_paths(revnum)
def get_revision_paths(self, revnum):
"""Obtain dictionary with all the changes in a particular revision.
@@ -619,9 +623,7 @@
if revnum > 0:
has_all_revprops = self.cache.has_all_revprops(revnum)
- known_revprops = {}
- for k,v in self.cache.get_revprops(revnum):
- known_revprops[k.encode("utf-8")] = v.encode("utf-8")
+ known_revprops = self.cache.get_revprops(revnum)
else:
has_all_revprops = False
known_revprops = {}
=== modified file 'tests/test_logwalker.py'
--- a/tests/test_logwalker.py 2008-06-23 18:41:27 +0000
+++ b/tests/test_logwalker.py 2008-06-23 20:10:24 +0000
@@ -20,6 +20,7 @@
import os
from bzrlib import urlutils, debug
+from bzrlib.tests import TestCase
from bzrlib.plugins.svn import logwalker, transport
from bzrlib.plugins.svn.tests import TestCaseWithSubversionRepository
@@ -71,6 +72,7 @@
assert parent != relpath
relpath = parent
+
class TestLogWalker(TestCaseWithSubversionRepository):
def setUp(self):
super(TestLogWalker, self).setUp()
@@ -1023,6 +1025,7 @@
def test_restricted_strict_move(self):
self.template_restricted(True, {'baz': True, '': False})
+
class TestCachingLogWalker(TestLogWalker):
def setUp(self):
super(TestCachingLogWalker, self).setUp()
@@ -1033,3 +1036,22 @@
return logwalker.CachingLogWalker(super(TestCachingLogWalker, self).get_log_walker(transport))
+
+class TestLogCache(TestCase):
+ def setUp(self):
+ super(TestLogCache, self).setUp()
+ self.cache = logwalker.LogCache()
+
+ def test_insert_path(self):
+ self.cache.insert_path(42, "foo", "A", None, -1)
+ self.assertEquals({"foo": ("A", None, -1)}, self.cache.get_revision_paths(42))
+
+ def test_insert_revprop(self):
+ self.cache.insert_revprop(100, "some", "data")
+ self.assertEquals({"some": "data"}, self.cache.get_revprops(100))
+
+ def test_insert_revinfo(self):
+ self.cache.insert_revinfo(45, True)
+ self.cache.insert_revinfo(42, False)
+ self.assertTrue(self.cache.has_all_revprops(45))
+ self.assertFalse(self.cache.has_all_revprops(42))
More information about the bazaar-commits
mailing list