Mercurial > python-hglib
annotate tests/test-update.py @ 179:c4c0efb37187
protocol: add the abilty to trace the protocol between the client and server
This is useful when debugging issues with driving hg via hglib
where output and error messages can be lost.
Call setprotocoltrace with the name of a trace function or None.
If the trace function is None no tracing is done.
The trace function is called with the direction, the channel-identified
and its data.
author | Barry A. Scott <barry@barrys-emacs.org> |
---|---|
date | Tue, 18 Oct 2016 17:45:17 +0100 |
parents | b91356bf7186 |
children |
rev | line source |
---|---|
148
c1b966866ed7
hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents:
143
diff
changeset
|
1 from tests import common |
20 | 2 from hglib import error |
151
b91356bf7186
hglib: use strtobytes() (issue4520)
Brett Cannon <brett@python.org>
parents:
148
diff
changeset
|
3 from hglib.util import b, strtobytes |
20 | 4 |
5 class test_update(common.basetest): | |
6 def setUp(self): | |
7 common.basetest.setUp(self) | |
8 self.append('a', 'a') | |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
9 self.rev0, self.node0 = self.client.commit(b('first'), addremove=True) |
20 | 10 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
11 self.rev1, self.node1 = self.client.commit(b('second')) |
20 | 12 |
13 def test_basic(self): | |
14 u, m, r, ur = self.client.update(self.rev0) | |
15 self.assertEquals(u, 1) | |
16 self.assertEquals(m, 0) | |
17 self.assertEquals(r, 0) | |
18 self.assertEquals(ur, 0) | |
19 | |
20 def test_unresolved(self): | |
21 self.client.update(self.rev0) | |
22 self.append('a', 'b') | |
23 u, m, r, ur = self.client.update() | |
24 self.assertEquals(u, 0) | |
25 self.assertEquals(m, 0) | |
26 self.assertEquals(r, 0) | |
27 self.assertEquals(ur, 1) | |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
28 self.assertTrue((b('M'), b('a')) in self.client.status()) |
20 | 29 |
30 def test_merge(self): | |
31 self.append('a', '\n\n\n\nb') | |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
32 rev2, node2 = self.client.commit(b('third')) |
20 | 33 self.append('a', 'b') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
34 self.client.commit(b('fourth')) |
20 | 35 self.client.update(rev2) |
36 old = open('a').read() | |
118
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
37 f = open('a', 'wb') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
38 f.write(b('a') + old.encode('latin-1')) |
118
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
39 f.close() |
20 | 40 u, m, r, ur = self.client.update() |
41 self.assertEquals(u, 0) | |
42 self.assertEquals(m, 1) | |
43 self.assertEquals(r, 0) | |
44 self.assertEquals(ur, 0) | |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
45 self.assertEquals(self.client.status(), [(b('M'), b('a'))]) |
20 | 46 |
47 def test_tip(self): | |
48 self.client.update(self.rev0) | |
49 u, m, r, ur = self.client.update() | |
50 self.assertEquals(u, 1) | |
51 self.assertEquals(self.client.parents()[0].node, self.node1) | |
52 | |
53 self.client.update(self.rev0) | |
54 self.append('a', 'b') | |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
55 rev2, node2 = self.client.commit(b('new head')) |
20 | 56 self.client.update(self.rev0) |
57 | |
58 self.client.update() | |
59 self.assertEquals(self.client.parents()[0].node, node2) | |
60 | |
61 def test_check_clean(self): | |
134 | 62 self.assertRaises(ValueError, self.client.update, clean=True, |
63 check=True) | |
20 | 64 |
65 def test_clean(self): | |
66 old = open('a').read() | |
67 self.append('a', 'b') | |
68 self.assertRaises(error.CommandError, self.client.update, check=True) | |
69 | |
70 u, m, r, ur = self.client.update(clean=True) | |
71 self.assertEquals(u, 1) | |
72 self.assertEquals(old, open('a').read()) | |
105
86ff8611a8fa
client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents:
68
diff
changeset
|
73 |
86ff8611a8fa
client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents:
68
diff
changeset
|
74 def test_basic_plain(self): |
118
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
75 f = open('.hg/hgrc', 'a') |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
76 f.write('[defaults]\nupdate=-v\n') |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
77 f.close() |
105
86ff8611a8fa
client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents:
68
diff
changeset
|
78 self.test_basic() |
109
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
79 |
140
9c4f52467208
tests: disable largefiles test in update
Matt Mackall <mpm@selenic.com>
parents:
134
diff
changeset
|
80 def disabled_largefiles(self): |
9c4f52467208
tests: disable largefiles test in update
Matt Mackall <mpm@selenic.com>
parents:
134
diff
changeset
|
81 # we don't run reposetup after a session has started, so this |
9c4f52467208
tests: disable largefiles test in update
Matt Mackall <mpm@selenic.com>
parents:
134
diff
changeset
|
82 # test is broken |
109
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
83 import os |
118
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
84 f = open('.hg/hgrc', 'a') |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
85 f.write('[extensions]\nlargefiles=\n') |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
115
diff
changeset
|
86 f.close() |
109
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
87 self.append('b', 'a') |
115
8867908fe8c7
tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents:
109
diff
changeset
|
88 try: |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
89 self.client.rawcommand([b('add'), b('b'), b('--large')]) |
115
8867908fe8c7
tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents:
109
diff
changeset
|
90 except error.CommandError: |
8867908fe8c7
tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents:
109
diff
changeset
|
91 return |
8867908fe8c7
tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents:
109
diff
changeset
|
92 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
140
diff
changeset
|
93 rev2, node2 = self.client.commit(b('third')) |
109
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
94 # Go back to 0 |
151
b91356bf7186
hglib: use strtobytes() (issue4520)
Brett Cannon <brett@python.org>
parents:
148
diff
changeset
|
95 self.client.rawcommand([b('update'), strtobytes(self.rev0)], |
109
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
96 # Keep the 'changed' version |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
97 prompt=lambda s, d: 'c\n') |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
98 u, m, r, ur = self.client.update(rev2, clean=True) |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
99 self.assertEquals(u, 2) |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
100 self.assertEquals(m, 0) |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
101 self.assertEquals(r, 0) |
9324a89dd84e
client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents:
105
diff
changeset
|
102 self.assertEquals(ur, 0) |