[PATCH 2 of 5] test-revert: move embedded script to its own file

Martin von Zweigbergk martinvonz at google.com
Tue Nov 4 23:39:30 CST 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1415060821 28800
#      Mon Nov 03 16:27:01 2014 -0800
# Node ID 8fc193357148dbada65bb444e41af33de7a8517a
# Parent  ca5b0e0681a5495057b3e45fc0d1abeb2f638f80
test-revert: move embedded script to its own file

Move the gen-revert-cases.py out of test-revert.t into its own file so
we can reuse it from other tests (specifically test-status-rev.t).

diff --git a/tests/generate-working-copy-states.py b/tests/generate-working-copy-states.py
new file mode 100644
--- /dev/null
+++ b/tests/generate-working-copy-states.py
@@ -0,0 +1,50 @@
+# generate proper file state to test working copy behavior
+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 (False, True):
+                def statestring(content):
+                    return content is None and 'missing' or content
+                trackedstring = tracked and 'tracked' or 'untracked'
+                filename = "%s_%s_%s-%s" % (statestring(base),
+                                            statestring(parent),
+                                            statestring(wcc),
+                                            trackedstring)
+                combination.append((filename, base, parent, wcc))
+
+# make sure we have stable output
+combination.sort()
+
+# retrieve the state we must generate
+target = sys.argv[1]
+
+# compute file content
+content = []
+for filename, base, parent, wcc in combination:
+    if target == 'filelist':
+        print filename
+    elif target == 'base':
+        content.append((filename, base))
+    elif target == 'parent':
+        content.append((filename, parent))
+    elif target == 'wc':
+        # Make sure there is content so the file gets written and can be
+        # tracked. It will be deleted outside of this script.
+        content.append((filename, wcc or 'TOBEDELETED'))
+    else:
+        print >> sys.stderr, "unknown target:", target
+        sys.exit(1)
+
+# write actual content
+for filename, data in content:
+    if data is not None:
+        f = open(filename, 'w')
+        f.write(data + '\n')
+        f.close()
+    elif os.path.exists(filename):
+        os.remove(filename)
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -422,62 +422,9 @@
 Write the python script to disk
 -------------------------------
 
-  $ cat << EOF > gen-revert-cases.py
-  > # generate proper file state to test revert behavior
-  > 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 (False, True):
-  >                 def statestring(content):
-  >                     return content is None and 'missing' or content
-  >                 trackedstring = tracked and 'tracked' or 'untracked'
-  >                 filename = "%s_%s_%s-%s" % (statestring(base),
-  >                                             statestring(parent),
-  >                                             statestring(wcc),
-  >                                             trackedstring)
-  >                 combination.append((filename, base, parent, wcc))
-  > 
-  > # make sure we have stable output
-  > combination.sort()
-  > 
-  > # retrieve the state we must generate
-  > target = sys.argv[1]
-  > 
-  > # compute file content
-  > content = []
-  > for filename, base, parent, wcc in combination:
-  >     if target == 'filelist':
-  >         print filename
-  >     elif target == 'base':
-  >         content.append((filename, base))
-  >     elif target == 'parent':
-  >         content.append((filename, parent))
-  >     elif target == 'wc':
-  >         # Make sure there is content so the file gets written and can be
-  >         # tracked. It will be deleted outside of this script.
-  >         content.append((filename, wcc or 'TOBEDELETED'))
-  >     else:
-  >         print >> sys.stderr, "unknown target:", target
-  >         sys.exit(1)
-  > 
-  > # write actual content
-  > for filename, data in content:
-  >     if data is not None:
-  >         f = open(filename, 'w')
-  >         f.write(data + '\n')
-  >         f.close()
-  >     elif os.path.exists(filename):
-  >        os.remove(filename)
-  > EOF
-
 check list of planned files
 
-  $ python gen-revert-cases.py filelist
+  $ python $TESTDIR/generate-working-copy-states.py filelist
   content1_content1_content1-tracked
   content1_content1_content1-untracked
   content1_content1_content3-tracked
@@ -532,7 +479,7 @@
 
 Generate base changeset
 
-  $ python ../gen-revert-cases.py base
+  $ python $TESTDIR/generate-working-copy-states.py base
   $ hg addremove --similarity 0
   adding content1_content1_content1-tracked
   adding content1_content1_content1-untracked
@@ -604,7 +551,7 @@
 
 Create parent changeset
 
-  $ python ../gen-revert-cases.py parent
+  $ python $TESTDIR/generate-working-copy-states.py parent
   $ hg addremove --similarity 0
   removing content1_missing_content1-tracked
   removing content1_missing_content1-untracked
@@ -668,7 +615,7 @@
 
 Setup working directory
 
-  $ python ../gen-revert-cases.py wc
+  $ python $TESTDIR/generate-working-copy-states.py wc
   $ hg addremove --similarity 0
   adding content1_missing_content1-tracked
   adding content1_missing_content1-untracked
@@ -885,7 +832,7 @@
 revert all files individually and check the output
 (output is expected to be different than in the --all case)
 
-  $ for file in `python ../gen-revert-cases.py filelist`; do
+  $ for file in `python $TESTDIR/generate-working-copy-states.py filelist`; do
   >   echo '### revert for:' $file;
   >   hg revert $file;
   >   echo
@@ -978,7 +925,7 @@
 revert all files individually and check the output
 (output is expected to be different than in the --all case)
 
-  $ for file in `python ../gen-revert-cases.py filelist`; do
+  $ for file in `python $TESTDIR/generate-working-copy-states.py filelist`; do
   >   echo '### revert for:' $file;
   >   hg revert $file --rev 'desc(base)';
   >   echo


More information about the Mercurial-devel mailing list