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