Patchwork [08,of,10,V2] revlog: add test case for _findsnapshots

login
register
mail settings
Submitter Boris Feld
Date Dec. 21, 2018, 11:47 a.m.
Message ID <c66cdd39a79c6165a145.1545392831@localhost.localdomain>
Download mbox | patch
Permalink /patch/37300/
State Accepted
Headers show

Comments

Boris Feld - Dec. 21, 2018, 11:47 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1545366450 -3600
#      Fri Dec 21 05:27:30 2018 +0100
# Node ID c66cdd39a79c6165a145cf94e4a3977f78588811
# Parent  4b515705427c5ce7f4d55611738ab7f62662dc6b
# EXP-Topic sparse-revlog
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c66cdd39a79c
revlog: add test case for _findsnapshots

Testing the method directly is more robust.

Patch

diff --git a/tests/test-revlog-raw.py b/tests/test-revlog-raw.py
--- a/tests/test-revlog-raw.py
+++ b/tests/test-revlog-raw.py
@@ -2,6 +2,7 @@ 
 
 from __future__ import absolute_import, print_function
 
+import collections
 import hashlib
 import sys
 
@@ -397,6 +398,24 @@  def issnapshottest(rlog):
         print('  expected: %s' % snapshots)
         print('  got:      %s' % result)
 
+snapshotmapall = {0: [6, 8, 11, 17, 19, 25], 8: [21], -1: [0, 30]}
+snapshotmap15 = {0: [17, 19, 25], 8: [21], -1: [30]}
+def findsnapshottest(rlog):
+    resultall = collections.defaultdict(list)
+    deltas._findsnapshots(rlog, resultall, 0)
+    resultall = dict(resultall.items())
+    if resultall != snapshotmapall:
+        print('snapshot map  differ:')
+        print('  expected: %s' % snapshotmapall)
+        print('  got:      %s' % resultall)
+    result15 = collections.defaultdict(list)
+    deltas._findsnapshots(rlog, result15, 15)
+    result15 = dict(result15.items())
+    if result15 != snapshotmap15:
+        print('snapshot map  differ:')
+        print('  expected: %s' % snapshotmap15)
+        print('  got:      %s' % result15)
+
 def maintest():
     expected = rl = None
     with newtransaction() as tr:
@@ -424,6 +443,8 @@  def maintest():
         rl5 = makesnapshot(tr)
         issnapshottest(rl5)
         print('issnapshot test passed')
+        findsnapshottest(rl5)
+        print('findsnapshot test passed')
 
 try:
     maintest()
diff --git a/tests/test-revlog-raw.py.out b/tests/test-revlog-raw.py.out
--- a/tests/test-revlog-raw.py.out
+++ b/tests/test-revlog-raw.py.out
@@ -4,3 +4,4 @@  clone test passed
 lowlevelcopy test passed
 slicing test passed
 issnapshot test passed
+findsnapshot test passed