comparison 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
comparison
equal deleted inserted replaced
220:ae6427d1c8f7 221:a2afbf236ca8
10 self.append('a', 'a') 10 self.append('a', 'a')
11 self.rev1, self.node1 = self.client.commit(b('second')) 11 self.rev1, self.node1 = self.client.commit(b('second'))
12 12
13 def test_basic(self): 13 def test_basic(self):
14 u, m, r, ur = self.client.update(self.rev0) 14 u, m, r, ur = self.client.update(self.rev0)
15 self.assertEquals(u, 1) 15 self.assertEqual(u, 1)
16 self.assertEquals(m, 0) 16 self.assertEqual(m, 0)
17 self.assertEquals(r, 0) 17 self.assertEqual(r, 0)
18 self.assertEquals(ur, 0) 18 self.assertEqual(ur, 0)
19 19
20 def test_unresolved(self): 20 def test_unresolved(self):
21 self.client.update(self.rev0) 21 self.client.update(self.rev0)
22 self.append('a', 'b') 22 self.append('a', 'b')
23 u, m, r, ur = self.client.update() 23 u, m, r, ur = self.client.update()
24 self.assertEquals(u, 0) 24 self.assertEqual(u, 0)
25 self.assertEquals(m, 0) 25 self.assertEqual(m, 0)
26 self.assertEquals(r, 0) 26 self.assertEqual(r, 0)
27 self.assertEquals(ur, 1) 27 self.assertEqual(ur, 1)
28 self.assertTrue((b('M'), b('a')) in self.client.status()) 28 self.assertTrue((b('M'), b('a')) in self.client.status())
29 29
30 def test_merge(self): 30 def test_merge(self):
31 self.append('a', '\n\n\n\nb') 31 self.append('a', '\n\n\n\nb')
32 rev2, node2 = self.client.commit(b('third')) 32 rev2, node2 = self.client.commit(b('third'))
33 self.append('a', 'b') 33 self.append('a', 'b')
34 self.client.commit(b('fourth')) 34 self.client.commit(b('fourth'))
35 self.client.update(rev2) 35 self.client.update(rev2)
36 old = open('a').read() 36 with open('a') as f:
37 old = f.read()
37 f = open('a', 'wb') 38 f = open('a', 'wb')
38 f.write(b('a') + old.encode('latin-1')) 39 f.write(b('a') + old.encode('latin-1'))
39 f.close() 40 f.close()
40 u, m, r, ur = self.client.update() 41 u, m, r, ur = self.client.update()
41 self.assertEquals(u, 0) 42 self.assertEqual(u, 0)
42 self.assertEquals(m, 1) 43 self.assertEqual(m, 1)
43 self.assertEquals(r, 0) 44 self.assertEqual(r, 0)
44 self.assertEquals(ur, 0) 45 self.assertEqual(ur, 0)
45 self.assertEquals(self.client.status(), [(b('M'), b('a'))]) 46 self.assertEqual(self.client.status(), [(b('M'), b('a'))])
46 47
47 def test_tip(self): 48 def test_tip(self):
48 self.client.update(self.rev0) 49 self.client.update(self.rev0)
49 u, m, r, ur = self.client.update() 50 u, m, r, ur = self.client.update()
50 self.assertEquals(u, 1) 51 self.assertEqual(u, 1)
51 self.assertEquals(self.client.parents()[0].node, self.node1) 52 self.assertEqual(self.client.parents()[0].node, self.node1)
52 53
53 self.client.update(self.rev0) 54 self.client.update(self.rev0)
54 self.append('a', 'b') 55 self.append('a', 'b')
55 rev2, node2 = self.client.commit(b('new head')) 56 rev2, node2 = self.client.commit(b('new head'))
56 self.client.update(self.rev0) 57 self.client.update(self.rev0)
57 58
58 self.client.update() 59 self.client.update()
59 self.assertEquals(self.client.parents()[0].node, node2) 60 self.assertEqual(self.client.parents()[0].node, node2)
60 61
61 def test_check_clean(self): 62 def test_check_clean(self):
62 self.assertRaises(ValueError, self.client.update, clean=True, 63 self.assertRaises(ValueError, self.client.update, clean=True,
63 check=True) 64 check=True)
64 65
65 def test_clean(self): 66 def test_clean(self):
66 old = open('a').read() 67 with open('a') as f:
68 old = f.read()
67 self.append('a', 'b') 69 self.append('a', 'b')
68 self.assertRaises(error.CommandError, self.client.update, check=True) 70 self.assertRaises(error.CommandError, self.client.update, check=True)
69 71
70 u, m, r, ur = self.client.update(clean=True) 72 u, m, r, ur = self.client.update(clean=True)
71 self.assertEquals(u, 1) 73 self.assertEqual(u, 1)
72 self.assertEquals(old, open('a').read()) 74 with open('a') as f:
75 self.assertEqual(old, f.read())
73 76
74 def test_basic_plain(self): 77 def test_basic_plain(self):
75 f = open('.hg/hgrc', 'a') 78 f = open('.hg/hgrc', 'a')
76 f.write('[defaults]\nupdate=-v\n') 79 f.write('[defaults]\nupdate=-v\n')
77 f.close() 80 f.close()
94 # Go back to 0 97 # Go back to 0
95 self.client.rawcommand([b('update'), strtobytes(self.rev0)], 98 self.client.rawcommand([b('update'), strtobytes(self.rev0)],
96 # Keep the 'changed' version 99 # Keep the 'changed' version
97 prompt=lambda s, d: 'c\n') 100 prompt=lambda s, d: 'c\n')
98 u, m, r, ur = self.client.update(rev2, clean=True) 101 u, m, r, ur = self.client.update(rev2, clean=True)
99 self.assertEquals(u, 2) 102 self.assertEqual(u, 2)
100 self.assertEquals(m, 0) 103 self.assertEqual(m, 0)
101 self.assertEquals(r, 0) 104 self.assertEqual(r, 0)
102 self.assertEquals(ur, 0) 105 self.assertEqual(ur, 0)