annotate tests/test_update.py @ 221:a2afbf236ca8

hglib tests: remove deprecated constructions This mostly removes usage of 'assertEquals' (replaced with 'assertEqual'), as well as opening files without closing them (fixed using a 'with' statement).
author Mathias De Mare <mathias.de_mare@nokia.com>
date Thu, 09 Mar 2023 14:00:02 +0100
parents 8341f2494b3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5 class test_update(common.basetest):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
6 def setUp(self):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
7 common.basetest.setUp(self)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
12
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
13 def test_basic(self):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
14 u, m, r, ur = self.client.update(self.rev0)
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
15 self.assertEqual(u, 1)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
16 self.assertEqual(m, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
17 self.assertEqual(r, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
18 self.assertEqual(ur, 0)
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
19
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
20 def test_unresolved(self):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
21 self.client.update(self.rev0)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
22 self.append('a', 'b')
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
23 u, m, r, ur = self.client.update()
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
24 self.assertEqual(u, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
25 self.assertEqual(m, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
26 self.assertEqual(r, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
27 self.assertEqual(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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
29
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
30 def test_merge(self):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
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
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
35 self.client.update(rev2)
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
36 with open('a') as f:
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
37 old = f.read()
118
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
38 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
39 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
40 f.close()
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
41 u, m, r, ur = self.client.update()
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
42 self.assertEqual(u, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
43 self.assertEqual(m, 1)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
44 self.assertEqual(r, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
45 self.assertEqual(ur, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
46 self.assertEqual(self.client.status(), [(b('M'), b('a'))])
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
48 def test_tip(self):
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
49 self.client.update(self.rev0)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
50 u, m, r, ur = self.client.update()
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
51 self.assertEqual(u, 1)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
52 self.assertEqual(self.client.parents()[0].node, self.node1)
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
53
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
54 self.client.update(self.rev0)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
55 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
56 rev2, node2 = self.client.commit(b('new head'))
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
57 self.client.update(self.rev0)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
58
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
59 self.client.update()
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
60 self.assertEqual(self.client.parents()[0].node, node2)
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
61
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
62 def test_check_clean(self):
134
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 118
diff changeset
63 self.assertRaises(ValueError, self.client.update, clean=True,
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 118
diff changeset
64 check=True)
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
65
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66 def test_clean(self):
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
67 with open('a') as f:
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
68 old = f.read()
20
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
69 self.append('a', 'b')
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
70 self.assertRaises(error.CommandError, self.client.update, check=True)
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
71
6a9d16ddae31 client: add update command
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
72 u, m, r, ur = self.client.update(clean=True)
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
73 self.assertEqual(u, 1)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
74 with open('a') as f:
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
75 self.assertEqual(old, f.read())
105
86ff8611a8fa client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents: 68
diff changeset
76
86ff8611a8fa client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents: 68
diff changeset
77 def test_basic_plain(self):
118
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
78 f = open('.hg/hgrc', 'a')
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
79 f.write('[defaults]\nupdate=-v\n')
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
80 f.close()
105
86ff8611a8fa client: always set HGPLAIN=1 (issue3502)
Siddharth Agarwal <sid0@fb.com>
parents: 68
diff changeset
81 self.test_basic()
109
9324a89dd84e client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents: 105
diff changeset
82
140
9c4f52467208 tests: disable largefiles test in update
Matt Mackall <mpm@selenic.com>
parents: 134
diff changeset
83 def disabled_largefiles(self):
9c4f52467208 tests: disable largefiles test in update
Matt Mackall <mpm@selenic.com>
parents: 134
diff changeset
84 # 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
85 # test is broken
109
9324a89dd84e client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents: 105
diff changeset
86 import os
118
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
87 f = open('.hg/hgrc', 'a')
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
88 f.write('[extensions]\nlargefiles=\n')
e738d6fe5f3f tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents: 115
diff changeset
89 f.close()
109
9324a89dd84e client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents: 105
diff changeset
90 self.append('b', 'a')
115
8867908fe8c7 tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents: 109
diff changeset
91 try:
143
4359cabcb0cc hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 140
diff changeset
92 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
93 except error.CommandError:
8867908fe8c7 tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents: 109
diff changeset
94 return
8867908fe8c7 tests: deal with missing largefiles support for 1.9
Matt Mackall <mpm@selenic.com>
parents: 109
diff changeset
95
143
4359cabcb0cc hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 140
diff changeset
96 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
97 # Go back to 0
151
b91356bf7186 hglib: use strtobytes() (issue4520)
Brett Cannon <brett@python.org>
parents: 148
diff changeset
98 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
99 # Keep the 'changed' version
9324a89dd84e client: Be more permissive on the output of update (issue3892)
Benoit Allard <benoit@aeteurope.nl>
parents: 105
diff changeset
100 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
101 u, m, r, ur = self.client.update(rev2, clean=True)
221
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
102 self.assertEqual(u, 2)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
103 self.assertEqual(m, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
104 self.assertEqual(r, 0)
a2afbf236ca8 hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 219
diff changeset
105 self.assertEqual(ur, 0)