Mercurial > python-hglib
annotate tests/test-context.py @ 136:dc63978871ed
client: add support for 'hg commit --amend'
author | David Douard <david.douard@logilab.fr> |
---|---|
date | Thu, 23 Oct 2014 10:50:09 +0200 |
parents | b6f601ba7f3c |
children | 4359cabcb0cc |
rev | line source |
---|---|
128
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
1 import sys |
110
c635e6e7054f
context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents:
95
diff
changeset
|
2 from hglib.error import CommandError |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 import common, hglib |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 from hglib import context |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 class test_context(common.basetest): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 def test_non_existent(self): |
113
27591b5bb9d9
tests: remove usage of assertRaisesRegexp
Alexander Plavin <me@aplavin.ru>
parents:
110
diff
changeset
|
8 self.assertRaises(ValueError, context.changectx, self.client, 'foo') |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 def test_basic(self): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 self.append('a', 'a') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 self.append('b', 'b') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 rev0, node0 = self.client.commit('first', addremove=True) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 self.append('c', 'c') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 rev1, node1 = self.client.commit('second', addremove=True) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
95
bd23bc72e662
client: add a convenience method __getitem__ to return a changectx
Idan Kamara <idankk86@gmail.com>
parents:
94
diff
changeset
|
18 ctx = self.client[node0] |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 self.assertEquals(ctx.description(), 'first') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 self.assertEquals(str(ctx), node0[:12]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 self.assertEquals(ctx.node(), node0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 self.assertEquals(int(ctx), rev0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 self.assertEquals(ctx.rev(), rev0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 self.assertEquals(ctx.branch(), 'default') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 self.assertTrue(ctx) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 self.assertTrue('a' in ctx and 'b' in ctx) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 self.assertFalse('c' in ctx) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 self.assertEquals(list(ctx), ['a', 'b']) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 self.assertEquals(ctx.files(), ['a', 'b']) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 self.assertEquals(ctx.modified(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 self.assertEquals(ctx.added(), ['a', 'b']) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 self.assertEquals(ctx.removed(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 self.assertEquals(ctx.ignored(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 self.assertEquals(ctx.clean(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 man = {'a' : '047b75c6d7a3ef6a2243bd0e99f94f6ea6683597', |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 'b' : '62452855512f5b81522aa3895892760bb8da9f3f'} |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 self.assertEquals(ctx.manifest(), man) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 self.assertEquals([int(c) for c in ctx.parents()], [-1]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 self.assertEquals(int(ctx.p1()), -1) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 self.assertEquals(int(ctx.p2()), -1) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 self.assertEquals([int(c) for c in ctx.children()], [1]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 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
|
50 self.assertEquals([int(c) for c in ctx.ancestors()], [0]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
51 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
52 self.client.bookmark('bookmark', inactive=True, rev=node0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
53 self.assertEquals(ctx.bookmarks(), ['bookmark']) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
54 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
55 self.client.tag('tag', rev=node0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
56 # 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
|
57 self.assertEquals(self.client[node0].tags(), ['tag']) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
58 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
59 def test_construction(self): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
60 self.append('a', 'a') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
61 rev0, node0 = self.client.commit('first', addremove=True) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
62 tip = self.client.tip() |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
63 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
64 # from client.revision |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
65 ctx = context.changectx(self.client, tip) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
66 self.assertEquals(ctx.node(), tip.node) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
67 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
68 # from revset |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
69 ctx = context.changectx(self.client, 'all()') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
70 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
|
71 |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
72 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
|
73 """ |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
74 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
|
75 """ |
128
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
76 if sys.version_info < (2, 7): |
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
77 return |
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
78 |
122
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
79 self.append('a', 'a') |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
80 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
|
81 self.append('a', 'a') |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
82 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
|
83 |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 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
|
88 hash_2 = self.client.log(1)[0][1] |
133 | 89 self.assertIn(hash_2, self.client) |
122
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
90 hash_2 = 'deadbeef' |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
91 self.assertNotIn(hash_2, self.client) |