comparison tests/test-commit.py @ 143:4359cabcb0cc

hglib: move string literals in the test code to util.b() (issue4520)
author Brett Cannon <brett@python.org>
date Mon, 09 Mar 2015 18:26:25 -0400
parents dc63978871ed
children 3c59643a2bc3
comparison
equal deleted inserted replaced
142:fe74d5599539 143:4359cabcb0cc
1 import common, hglib, datetime 1 import common, hglib, datetime
2 from hglib.util import b
2 3
3 class test_commit(common.basetest): 4 class test_commit(common.basetest):
4 def test_user(self): 5 def test_user(self):
5 self.append('a', 'a') 6 self.append('a', 'a')
6 rev, node = self.client.commit('first', addremove=True, user='foo') 7 rev, node = self.client.commit(b('first'), addremove=True,
8 user=b('foo'))
7 rev = self.client.log(node)[0] 9 rev = self.client.log(node)[0]
8 self.assertEquals(rev.author, 'foo') 10 self.assertEquals(rev.author, b('foo'))
9 11
10 def test_no_user(self): 12 def test_no_user(self):
11 self.append('a', 'a') 13 self.append('a', 'a')
12 self.assertRaises(hglib.error.CommandError, 14 self.assertRaises(hglib.error.CommandError,
13 self.client.commit, 'first', user='') 15 self.client.commit, b('first'), user=b(''))
14 16
15 def test_close_branch(self): 17 def test_close_branch(self):
16 self.append('a', 'a') 18 self.append('a', 'a')
17 rev0, node0 = self.client.commit('first', addremove=True) 19 rev0, node0 = self.client.commit(b('first'), addremove=True)
18 self.client.branch('foo') 20 self.client.branch(b('foo'))
19 self.append('a', 'a') 21 self.append('a', 'a')
20 rev1, node1 = self.client.commit('second') 22 rev1, node1 = self.client.commit(b('second'))
21 revclose = self.client.commit('closing foo', closebranch=True) 23 revclose = self.client.commit(b('closing foo'), closebranch=True)
22 rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]]) 24 rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]])
23 25
24 self.assertEquals(self.client.branches(), 26 self.assertEquals(self.client.branches(),
25 [(rev0.branch, int(rev0.rev), rev0.node[:12])]) 27 [(rev0.branch, int(rev0.rev), rev0.node[:12])])
26 28
28 [(revclose.branch, int(revclose.rev), 30 [(revclose.branch, int(revclose.rev),
29 revclose.node[:12]), 31 revclose.node[:12]),
30 (rev0.branch, int(rev0.rev), rev0.node[:12])]) 32 (rev0.branch, int(rev0.rev), rev0.node[:12])])
31 33
32 def test_message_logfile(self): 34 def test_message_logfile(self):
33 self.assertRaises(ValueError, self.client.commit, 'foo', logfile='bar') 35 self.assertRaises(ValueError, self.client.commit, b('foo'),
36 logfile=b('bar'))
34 self.assertRaises(ValueError, self.client.commit) 37 self.assertRaises(ValueError, self.client.commit)
35 38
36 def test_date(self): 39 def test_date(self):
37 self.append('a', 'a') 40 self.append('a', 'a')
38 now = datetime.datetime.now().replace(microsecond=0) 41 now = datetime.datetime.now().replace(microsecond=0)
39 rev0, node0 = self.client.commit('first', addremove=True, 42 rev0, node0 = self.client.commit(
40 date=now.isoformat(' ')) 43 b('first'), addremove=True,
44 date=now.isoformat(' ').encode('latin-1'))
41 45
42 self.assertEquals(now, self.client.tip().date) 46 self.assertEquals(now, self.client.tip().date)
43 47
44 def test_amend(self): 48 def test_amend(self):
45 self.append('a', 'a') 49 self.append('a', 'a')
46 now = datetime.datetime.now().replace(microsecond=0) 50 now = datetime.datetime.now().replace(microsecond=0)
47 rev0, node0 = self.client.commit('first', addremove=True, 51 rev0, node0 = self.client.commit(
48 date=now.isoformat(' ')) 52 b('first'), addremove=True,
53 date=now.isoformat(' ').encode('latin-1'))
49 54
50 print rev0, node0 55 print rev0, node0
51 self.assertEquals(now, self.client.tip().date) 56 self.assertEquals(now, self.client.tip().date)
52 57
53 self.append('a', 'a') 58 self.append('a', 'a')
54 rev1, node1 = self.client.commit(amend=True) 59 rev1, node1 = self.client.commit(amend=True)
55 print rev1, node1 60 print rev1, node1
56 self.assertEquals(now, self.client.tip().date) 61 self.assertEquals(now, self.client.tip().date)
57 self.assertNotEquals(node0, node1) 62 self.assertNotEquals(node0, node1)
58 self.assertEqual(1, len(self.client.log())) 63 self.assertEqual(1, len(self.client.log()))
59