annotate tests/test-context.py @ 209:522cefa8cb45

tox: add a tox.ini for easier testing of hglib against many hg versions
author Augie Fackler <raf@durin42.com>
date Thu, 23 May 2019 12:42:50 -0400
parents 3f854e3bcdd1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
176
3f854e3bcdd1 client: raise KeyError from __getitem__ (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 148
diff changeset
20 self.assertRaises(KeyError, self.client.__getitem__, 'doesnotexist')
3f854e3bcdd1 client: raise KeyError from __getitem__ (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 148
diff changeset
21
95
bd23bc72e662 client: add a convenience method __getitem__ to return a changectx
Idan Kamara <idankk86@gmail.com>
parents: 94
diff changeset
22 ctx = self.client[node0]
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
23
143
4359cabcb0cc hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 133
diff changeset
24 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
25 self.assertEquals(str(ctx), node0[:12].decode('latin-1'))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
26 self.assertEquals(ctx.node(), node0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
27 self.assertEquals(int(ctx), rev0)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
28 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
29 self.assertEquals(ctx.branch(), b('default'))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
30
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
31 self.assertTrue(ctx)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
32
143
4359cabcb0cc hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 133
diff changeset
33 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
34 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
35 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
36 self.assertEquals(ctx.files(), [b('a'), b('b')])
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
37
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
38 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
39 self.assertEquals(ctx.added(), [b('a'), b('b')])
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
40 self.assertEquals(ctx.removed(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
41 self.assertEquals(ctx.ignored(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
42 self.assertEquals(ctx.clean(), [])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43
143
4359cabcb0cc hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 133
diff changeset
44 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
45 b('b') : b('62452855512f5b81522aa3895892760bb8da9f3f')}
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46 self.assertEquals(ctx.manifest(), man)
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.parents()], [-1])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
49 self.assertEquals(int(ctx.p1()), -1)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
50 self.assertEquals(int(ctx.p2()), -1)
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.assertEquals([int(c) for c in ctx.children()], [1])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
53 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
54 self.assertEquals([int(c) for c in ctx.ancestors()], [0])
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.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
57 self.assertEquals(ctx.bookmarks(), [b('bookmark')])
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
58
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.client.tag(b('tag'), rev=node0)
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
60 # 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
61 self.assertEquals(self.client[node0].tags(), [b('tag')])
94
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 def test_construction(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
64 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
65 rev0, node0 = self.client.commit(b('first'), addremove=True)
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66 tip = self.client.tip()
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 client.revision
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
69 ctx = context.changectx(self.client, tip)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
70 self.assertEquals(ctx.node(), tip.node)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
71
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
72 # 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
73 ctx = context.changectx(self.client, b('all()'))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
74 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
75
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
76 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
77 """
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
78 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
79 """
128
838c5a91ed44 tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents: 122
diff changeset
80 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
81 return
838c5a91ed44 tests: skip test using assertIn on Python < 2.7
Matt Mackall <mpm@selenic.com>
parents: 122
diff changeset
82
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 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
85 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
86 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
87
e05b0cf920bb client: implement the 'in' keyword for a client object
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 113
diff changeset
88 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
89 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
90 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
91 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
92 hash_2 = self.client.log(1)[0][1]
133
b6f601ba7f3c style: fixup whitespace
Matt Mackall <mpm@selenic.com>
parents: 128
diff changeset
93 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
94 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
95 self.assertNotIn(hash_2, self.client)