Patchwork [2,of,5] generate-working-copy-states: generalize for depth

login
register
mail settings
Submitter Martin von Zweigbergk
Date Dec. 1, 2014, 6:14 a.m.
Message ID <ca7817e83c7fa92036b9.1417414497@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/6929/
State Accepted
Headers show

Comments

Martin von Zweigbergk - Dec. 1, 2014, 6:14 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1415518674 28800
#      Sat Nov 08 23:37:54 2014 -0800
# Node ID ca7817e83c7fa92036b96ab000a8b57a69313d0e
# Parent  678ce9eea4ef12eaa369a9ea2a5b2d256cb797a5
generate-working-copy-states: generalize for depth

The script can currently generate filenames and contents for exactly
two changesets plus the working copy. For some tests (e.g. of plain
dirstate status), only one changeset is needed, while for others
(e.g. merge), three changesets are needed. Let's prepare for such
tests by generalizing the code for any number of changesets.

Patch

diff --git a/tests/generate-working-copy-states.py b/tests/generate-working-copy-states.py
--- a/tests/generate-working-copy-states.py
+++ b/tests/generate-working-copy-states.py
@@ -2,29 +2,34 @@ 
 import sys
 import os
 
-# build the combination of possible states
-combination = []
-for base in [None, 'content1']:
-    for parent in set([None, 'content2']) | set([base]):
-        for wcc in set([None, 'content3']) | set([base, parent]):
-            for tracked in ('untracked', 'tracked'):
-                def statestring(content):
-                    return content is None and 'missing' or content
-                filename = "%s_%s_%s-%s" % (statestring(base),
-                                            statestring(parent),
-                                            statestring(wcc),
-                                            tracked)
-                combination.append((filename, base, parent, wcc))
+# Generates pairs of (filename, contents), where 'contents' is a list
+# describing the file's content at each revision (or in the working copy).
+# At each revision, it is either None or the file's actual content. When not
+# None, it may be either new content or the same content as an earlier
+# revisions, so all of (modified,clean,added,removed) can be tested.
+def generatestates(maxchangesets, parentcontents):
+    depth = len(parentcontents)
+    if depth == maxchangesets + 1:
+        for tracked in ('untracked', 'tracked'):
+            filename = "_".join([(content is None and 'missing' or content) for
+                                 content in parentcontents]) + "-" + tracked
+            yield (filename, parentcontents)
+    else:
+        for content in (set([None, 'content' + str(depth + 1)]) |
+                      set(parentcontents)):
+            for combination in generatestates(maxchangesets,
+                                              parentcontents + [content]):
+                yield combination
 
-# make sure we have stable output
-combination.sort()
+# sort to make sure we have stable output
+combinations = sorted(generatestates(2, []))
 
 # retrieve the state we must generate
 target = sys.argv[1]
 
 # compute file content
 content = []
-for filename, base, parent, wcc in combination:
+for filename, [base, parent, wcc] in combinations:
     if target == 'filelist':
         print filename
     elif target == 'base':