comparison tests/test-context.py @ 94:4da6bb8abfcc

context: initial implementation of changectx tries to mimic Mercurial's changectx
author Idan Kamara <idankk86@gmail.com>
date Thu, 22 Dec 2011 19:12:47 +0200
parents
children bd23bc72e662
comparison
equal deleted inserted replaced
93:a4fcece7dd8e 94:4da6bb8abfcc
1 import common, hglib
2 from hglib import context
3
4 class test_context(common.basetest):
5 def test_non_existent(self):
6 self.assertRaises(ValueError, context.changectx, self.client, 'foo')
7
8 def test_basic(self):
9 self.append('a', 'a')
10 self.append('b', 'b')
11 rev0, node0 = self.client.commit('first', addremove=True)
12
13 self.append('c', 'c')
14 rev1, node1 = self.client.commit('second', addremove=True)
15
16 ctx = context.changectx(self.client, node0)
17
18 self.assertEquals(ctx.description(), 'first')
19 self.assertEquals(str(ctx), node0[:12])
20 self.assertEquals(ctx.node(), node0)
21 self.assertEquals(int(ctx), rev0)
22 self.assertEquals(ctx.rev(), rev0)
23 self.assertEquals(ctx.branch(), 'default')
24
25 self.assertTrue(ctx)
26
27 self.assertTrue('a' in ctx and 'b' in ctx)
28 self.assertFalse('c' in ctx)
29 self.assertEquals(list(ctx), ['a', 'b'])
30 self.assertEquals(ctx.files(), ['a', 'b'])
31
32 self.assertEquals(ctx.modified(), [])
33 self.assertEquals(ctx.added(), ['a', 'b'])
34 self.assertEquals(ctx.removed(), [])
35 self.assertEquals(ctx.ignored(), [])
36 self.assertEquals(ctx.clean(), [])
37
38 man = {'a' : '047b75c6d7a3ef6a2243bd0e99f94f6ea6683597',
39 'b' : '62452855512f5b81522aa3895892760bb8da9f3f'}
40 self.assertEquals(ctx.manifest(), man)
41
42 self.assertEquals([int(c) for c in ctx.parents()], [-1])
43 self.assertEquals(int(ctx.p1()), -1)
44 self.assertEquals(int(ctx.p2()), -1)
45
46 self.assertEquals([int(c) for c in ctx.children()], [1])
47 self.assertEquals([int(c) for c in ctx.descendants()], [0, 1])
48 self.assertEquals([int(c) for c in ctx.ancestors()], [0])
49
50 self.client.bookmark('bookmark', inactive=True, rev=node0)
51 self.assertEquals(ctx.bookmarks(), ['bookmark'])
52
53 self.client.tag('tag', rev=node0)
54 # tags are read on construction
55 self.assertEquals(context.changectx(self.client, node0).tags(), ['tag'])
56
57 def test_construction(self):
58 self.append('a', 'a')
59 rev0, node0 = self.client.commit('first', addremove=True)
60 tip = self.client.tip()
61
62 # from client.revision
63 ctx = context.changectx(self.client, tip)
64 self.assertEquals(ctx.node(), tip.node)
65
66 # from revset
67 ctx = context.changectx(self.client, 'all()')
68 self.assertEquals(ctx.node(), tip.node)