Mercurial > public > mercurial-scm > python-hglib
annotate 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 |
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 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
5 from hglib.util import b |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 class test_context(common.basetest): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 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
|
9 self.assertRaises(ValueError, context.changectx, self.client, b('foo')) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 def test_basic(self): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 self.append('a', 'a') |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 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
|
14 rev0, node0 = self.client.commit(b('first'), addremove=True) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 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
|
17 rev1, node1 = self.client.commit(b('second'), addremove=True) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 |
95
bd23bc72e662
client: add a convenience method __getitem__ to return a changectx
Idan Kamara <idankk86@gmail.com>
parents:
94
diff
changeset
|
19 ctx = self.client[node0] |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
21 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
|
22 self.assertEquals(str(ctx), node0[:12].decode('latin-1')) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 self.assertEquals(ctx.node(), node0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 self.assertEquals(int(ctx), rev0) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 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
|
26 self.assertEquals(ctx.branch(), b('default')) |
94
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(ctx) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 self.assertEquals(ctx.files(), [b('a'), b('b')]) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 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
|
36 self.assertEquals(ctx.added(), [b('a'), b('b')]) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 self.assertEquals(ctx.removed(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 self.assertEquals(ctx.ignored(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 self.assertEquals(ctx.clean(), []) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
41 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
|
42 b('b') : b('62452855512f5b81522aa3895892760bb8da9f3f')} |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 self.assertEquals(ctx.manifest(), man) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 self.assertEquals([int(c) for c in ctx.parents()], [-1]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 self.assertEquals(int(ctx.p1()), -1) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 self.assertEquals(int(ctx.p2()), -1) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 self.assertEquals([int(c) for c in ctx.children()], [1]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
50 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
|
51 self.assertEquals([int(c) for c in ctx.ancestors()], [0]) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
52 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
53 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
|
54 self.assertEquals(ctx.bookmarks(), [b('bookmark')]) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
55 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
133
diff
changeset
|
56 self.client.tag(b('tag'), rev=node0) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
57 # 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
|
58 self.assertEquals(self.client[node0].tags(), [b('tag')]) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
59 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
60 def test_construction(self): |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
61 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
|
62 rev0, node0 = self.client.commit(b('first'), addremove=True) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
63 tip = self.client.tip() |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
64 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
65 # from client.revision |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
66 ctx = context.changectx(self.client, tip) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
67 self.assertEquals(ctx.node(), tip.node) |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
68 |
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
69 # 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
|
70 ctx = context.changectx(self.client, b('all()')) |
94
4da6bb8abfcc
context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
71 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
|
72 |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
73 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
|
74 """ |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
75 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
|
76 """ |
128
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
77 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
|
78 return |
838c5a91ed44
tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents:
122
diff
changeset
|
79 |
122
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 |
e05b0cf920bb
client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents:
113
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 hash_2 = self.client.log(1)[0][1] |
133 | 90 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
|
91 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
|
92 self.assertNotIn(hash_2, self.client) |