Mercurial > hg
annotate tests/generate-working-copy-states.py @ 23195:29977b315be1
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).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 03 Nov 2014 16:27:01 -0800 |
parents | |
children | 390a2610eaef |
rev | line source |
---|---|
23195
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
1 # generate proper file state to test working copy behavior |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
2 import sys |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
3 import os |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
4 |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
5 # build the combination of possible states |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
6 combination = [] |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
7 for base in [None, 'content1']: |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
8 for parent in set([None, 'content2']) | set([base]): |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
9 for wcc in set([None, 'content3']) | set([base, parent]): |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
10 for tracked in (False, True): |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
11 def statestring(content): |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
12 return content is None and 'missing' or content |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
13 trackedstring = tracked and 'tracked' or 'untracked' |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
14 filename = "%s_%s_%s-%s" % (statestring(base), |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
15 statestring(parent), |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
16 statestring(wcc), |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
17 trackedstring) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
18 combination.append((filename, base, parent, wcc)) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
19 |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
20 # make sure we have stable output |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
21 combination.sort() |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
22 |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
23 # retrieve the state we must generate |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
24 target = sys.argv[1] |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
25 |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
26 # compute file content |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
27 content = [] |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
28 for filename, base, parent, wcc in combination: |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
29 if target == 'filelist': |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
30 print filename |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
31 elif target == 'base': |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
32 content.append((filename, base)) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
33 elif target == 'parent': |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
34 content.append((filename, parent)) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
35 elif target == 'wc': |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
36 # Make sure there is content so the file gets written and can be |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
37 # tracked. It will be deleted outside of this script. |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
38 content.append((filename, wcc or 'TOBEDELETED')) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
39 else: |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
40 print >> sys.stderr, "unknown target:", target |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
41 sys.exit(1) |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
42 |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
43 # write actual content |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
44 for filename, data in content: |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
45 if data is not None: |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
46 f = open(filename, 'w') |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
47 f.write(data + '\n') |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
48 f.close() |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
49 elif os.path.exists(filename): |
29977b315be1
test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff
changeset
|
50 os.remove(filename) |