comparison tests/test-context.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 b6f601ba7f3c
children c1b966866ed7
comparison
equal deleted inserted replaced
142:fe74d5599539 143:4359cabcb0cc
1 import sys 1 import sys
2 from hglib.error import CommandError 2 from hglib.error import CommandError
3 import common, hglib 3 import common, hglib
4 from hglib import context 4 from hglib import context
5 from hglib.util import b
5 6
6 class test_context(common.basetest): 7 class test_context(common.basetest):
7 def test_non_existent(self): 8 def test_non_existent(self):
8 self.assertRaises(ValueError, context.changectx, self.client, 'foo') 9 self.assertRaises(ValueError, context.changectx, self.client, b('foo'))
9 10
10 def test_basic(self): 11 def test_basic(self):
11 self.append('a', 'a') 12 self.append('a', 'a')
12 self.append('b', 'b') 13 self.append('b', 'b')
13 rev0, node0 = self.client.commit('first', addremove=True) 14 rev0, node0 = self.client.commit(b('first'), addremove=True)
14 15
15 self.append('c', 'c') 16 self.append('c', 'c')
16 rev1, node1 = self.client.commit('second', addremove=True) 17 rev1, node1 = self.client.commit(b('second'), addremove=True)
17 18
18 ctx = self.client[node0] 19 ctx = self.client[node0]
19 20
20 self.assertEquals(ctx.description(), 'first') 21 self.assertEquals(ctx.description(), b('first'))
21 self.assertEquals(str(ctx), node0[:12]) 22 self.assertEquals(str(ctx), node0[:12].decode('latin-1'))
22 self.assertEquals(ctx.node(), node0) 23 self.assertEquals(ctx.node(), node0)
23 self.assertEquals(int(ctx), rev0) 24 self.assertEquals(int(ctx), rev0)
24 self.assertEquals(ctx.rev(), rev0) 25 self.assertEquals(ctx.rev(), rev0)
25 self.assertEquals(ctx.branch(), 'default') 26 self.assertEquals(ctx.branch(), b('default'))
26 27
27 self.assertTrue(ctx) 28 self.assertTrue(ctx)
28 29
29 self.assertTrue('a' in ctx and 'b' in ctx) 30 self.assertTrue(b('a') in ctx and b('b') in ctx)
30 self.assertFalse('c' in ctx) 31 self.assertFalse(b('c') in ctx)
31 self.assertEquals(list(ctx), ['a', 'b']) 32 self.assertEquals(list(ctx), [b('a'), b('b')])
32 self.assertEquals(ctx.files(), ['a', 'b']) 33 self.assertEquals(ctx.files(), [b('a'), b('b')])
33 34
34 self.assertEquals(ctx.modified(), []) 35 self.assertEquals(ctx.modified(), [])
35 self.assertEquals(ctx.added(), ['a', 'b']) 36 self.assertEquals(ctx.added(), [b('a'), b('b')])
36 self.assertEquals(ctx.removed(), []) 37 self.assertEquals(ctx.removed(), [])
37 self.assertEquals(ctx.ignored(), []) 38 self.assertEquals(ctx.ignored(), [])
38 self.assertEquals(ctx.clean(), []) 39 self.assertEquals(ctx.clean(), [])
39 40
40 man = {'a' : '047b75c6d7a3ef6a2243bd0e99f94f6ea6683597', 41 man = {b('a') : b('047b75c6d7a3ef6a2243bd0e99f94f6ea6683597'),
41 'b' : '62452855512f5b81522aa3895892760bb8da9f3f'} 42 b('b') : b('62452855512f5b81522aa3895892760bb8da9f3f')}
42 self.assertEquals(ctx.manifest(), man) 43 self.assertEquals(ctx.manifest(), man)
43 44
44 self.assertEquals([int(c) for c in ctx.parents()], [-1]) 45 self.assertEquals([int(c) for c in ctx.parents()], [-1])
45 self.assertEquals(int(ctx.p1()), -1) 46 self.assertEquals(int(ctx.p1()), -1)
46 self.assertEquals(int(ctx.p2()), -1) 47 self.assertEquals(int(ctx.p2()), -1)
47 48
48 self.assertEquals([int(c) for c in ctx.children()], [1]) 49 self.assertEquals([int(c) for c in ctx.children()], [1])
49 self.assertEquals([int(c) for c in ctx.descendants()], [0, 1]) 50 self.assertEquals([int(c) for c in ctx.descendants()], [0, 1])
50 self.assertEquals([int(c) for c in ctx.ancestors()], [0]) 51 self.assertEquals([int(c) for c in ctx.ancestors()], [0])
51 52
52 self.client.bookmark('bookmark', inactive=True, rev=node0) 53 self.client.bookmark(b('bookmark'), inactive=True, rev=node0)
53 self.assertEquals(ctx.bookmarks(), ['bookmark']) 54 self.assertEquals(ctx.bookmarks(), [b('bookmark')])
54 55
55 self.client.tag('tag', rev=node0) 56 self.client.tag(b('tag'), rev=node0)
56 # tags are read on construction 57 # tags are read on construction
57 self.assertEquals(self.client[node0].tags(), ['tag']) 58 self.assertEquals(self.client[node0].tags(), [b('tag')])
58 59
59 def test_construction(self): 60 def test_construction(self):
60 self.append('a', 'a') 61 self.append('a', 'a')
61 rev0, node0 = self.client.commit('first', addremove=True) 62 rev0, node0 = self.client.commit(b('first'), addremove=True)
62 tip = self.client.tip() 63 tip = self.client.tip()
63 64
64 # from client.revision 65 # from client.revision
65 ctx = context.changectx(self.client, tip) 66 ctx = context.changectx(self.client, tip)
66 self.assertEquals(ctx.node(), tip.node) 67 self.assertEquals(ctx.node(), tip.node)
67 68
68 # from revset 69 # from revset
69 ctx = context.changectx(self.client, 'all()') 70 ctx = context.changectx(self.client, b('all()'))
70 self.assertEquals(ctx.node(), tip.node) 71 self.assertEquals(ctx.node(), tip.node)
71 72
72 def test_in_keyword(self): 73 def test_in_keyword(self):
73 """ 74 """
74 test the 'in' keyword using both revision numbers or changeset ids. 75 test the 'in' keyword using both revision numbers or changeset ids.
75 """ 76 """
76 if sys.version_info < (2, 7): 77 if sys.version_info < (2, 7):
77 return 78 return
78 79
79 self.append('a', 'a') 80 self.append('a', 'a')
80 rev0, node0 = self.client.commit('first', addremove=True) 81 rev0, node0 = self.client.commit(b('first'), addremove=True)
81 self.append('a', 'a') 82 self.append('a', 'a')
82 rev1, node1 = self.client.commit('second') 83 rev1, node1 = self.client.commit(b('second'))
83 84
84 self.assertIn(1, self.client) 85 self.assertIn(1, self.client)
85 hash_1 = self.client.log(0)[0][1] 86 hash_1 = self.client.log(0)[0][1]
86 self.assertIn(hash_1, self.client) 87 self.assertIn(hash_1, self.client)
87 self.assertNotIn(2, self.client) 88 self.assertNotIn(2, self.client)
88 hash_2 = self.client.log(1)[0][1] 89 hash_2 = self.client.log(1)[0][1]
89 self.assertIn(hash_2, self.client) 90 self.assertIn(hash_2, self.client)
90 hash_2 = 'deadbeef' 91 hash_2 = b('deadbeef')
91 self.assertNotIn(hash_2, self.client) 92 self.assertNotIn(hash_2, self.client)