annotate tests/test-context.py @ 123:cdde1656346f

client: add 'hidden' property to show hidden changesets. This enables interactions with the obsolete changesets in the repository: - add the attribute in client class - add the keyword to the relevant commands - enable log without hidden changesets even when self.hidden is True - add a few tests with the hidden keyword This changeset mirrors the behavior of the mercurial global command --hidden: an attribute is added to the client library. If set at True, adds the hidden keyword to all command which can use it to show hidden changesets. The alternative would be to add the keyword in rawcommand, but the hidden flag is not relevant for commands such as add or branch.
author Paul Tonelli <paul.tonelli@logilab.fr>
date Thu, 22 May 2014 15:23:12 +0200
parents e05b0cf920bb
children 838c5a91ed44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 95
diff changeset
1 from hglib.error import CommandError
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
2 import common, hglib
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
3 from hglib import context
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5 class test_context(common.basetest):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
6 def test_non_existent(self):
113
27591b5bb9d9 tests: remove usage of assertRaisesRegexp
Alexander Plavin <me@aplavin.ru>
parents: 110
diff changeset
7 self.assertRaises(ValueError, context.changectx, self.client, 'foo')
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
8
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
9 def test_basic(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
10 self.append('a', 'a')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
11 self.append('b', 'b')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
12 rev0, node0 = self.client.commit('first', addremove=True)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
13
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
14 self.append('c', 'c')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
15 rev1, node1 = self.client.commit('second', addremove=True)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16
95
bd23bc72e662 client: add a convenience method __getitem__ to return a changectx
Idan Kamara <idankk86@gmail.com>
parents: 94
diff changeset
17 ctx = self.client[node0]
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
18
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
19 self.assertEquals(ctx.description(), 'first')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
20 self.assertEquals(str(ctx), node0[:12])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
21 self.assertEquals(ctx.node(), node0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
22 self.assertEquals(int(ctx), rev0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
23 self.assertEquals(ctx.rev(), rev0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
24 self.assertEquals(ctx.branch(), 'default')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
25
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
26 self.assertTrue(ctx)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
27
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
28 self.assertTrue('a' in ctx and 'b' in ctx)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
29 self.assertFalse('c' in ctx)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
30 self.assertEquals(list(ctx), ['a', 'b'])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
31 self.assertEquals(ctx.files(), ['a', 'b'])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
32
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
33 self.assertEquals(ctx.modified(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
34 self.assertEquals(ctx.added(), ['a', 'b'])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
35 self.assertEquals(ctx.removed(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
36 self.assertEquals(ctx.ignored(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
37 self.assertEquals(ctx.clean(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
38
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
39 man = {'a' : '047b75c6d7a3ef6a2243bd0e99f94f6ea6683597',
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
40 'b' : '62452855512f5b81522aa3895892760bb8da9f3f'}
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
41 self.assertEquals(ctx.manifest(), man)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
42
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43 self.assertEquals([int(c) for c in ctx.parents()], [-1])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
44 self.assertEquals(int(ctx.p1()), -1)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
45 self.assertEquals(int(ctx.p2()), -1)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47 self.assertEquals([int(c) for c in ctx.children()], [1])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
48 self.assertEquals([int(c) for c in ctx.descendants()], [0, 1])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
49 self.assertEquals([int(c) for c in ctx.ancestors()], [0])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
50
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
51 self.client.bookmark('bookmark', inactive=True, rev=node0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
52 self.assertEquals(ctx.bookmarks(), ['bookmark'])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
53
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
54 self.client.tag('tag', rev=node0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
55 # tags are read on construction
95
bd23bc72e662 client: add a convenience method __getitem__ to return a changectx
Idan Kamara <idankk86@gmail.com>
parents: 94
diff changeset
56 self.assertEquals(self.client[node0].tags(), ['tag'])
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
57
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
58 def test_construction(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
59 self.append('a', 'a')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
60 rev0, node0 = self.client.commit('first', addremove=True)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
61 tip = self.client.tip()
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
62
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
63 # from client.revision
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
64 ctx = context.changectx(self.client, tip)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
65 self.assertEquals(ctx.node(), tip.node)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
67 # from revset
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
68 ctx = context.changectx(self.client, 'all()')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
69 self.assertEquals(ctx.node(), tip.node)
122
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
70
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
71 def test_in_keyword(self):
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
72 """
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
73 test the 'in' keyword using both revision numbers or changeset ids.
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
74 """
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
75 self.append('a', 'a')
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
76 rev0, node0 = self.client.commit('first', addremove=True)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
77 self.append('a', 'a')
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
78 rev1, node1 = self.client.commit('second')
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
79
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
80 self.assertIn(1, self.client)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
81 hash_1 = self.client.log(0)[0][1]
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
82 self.assertIn(hash_1, self.client)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
83 self.assertNotIn(2, self.client)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
84 hash_2 = self.client.log(1)[0][1]
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
85 self.assertIn(hash_2,self.client)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
86 hash_2 = 'deadbeef'
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
87 self.assertNotIn(hash_2, self.client)
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
88
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
89