annotate tests/test-hglib.py @ 0:79f88b4db15f

Initial commit
author Idan Kamara <idankk86@gmail.com>
date Wed, 20 Jul 2011 16:09:34 -0500
parents
children 5fa34c3ac9a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
2
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
3 import unittest
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5 import sys, os, subprocess, cStringIO, shutil, tempfile
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
6
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
7 # XXX fix this hack
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
8 sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
9 from hglib import hglib
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
10
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
11 class test_hglib(unittest.TestCase):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
12 def setUp(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
13 self._tmpdir = tempfile.mkdtemp()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
14 os.chdir(self._tmpdir)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
15 # until we can run norepo commands in the cmdserver
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16 os.system('hg init')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
17 self.client = hglib.connect()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
18
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
19 def tearDown(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
20 shutil.rmtree(self._tmpdir)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
21
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
22 def append(self, path, *args):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
23 f = open(path, 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
24 for a in args:
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
25 f.write(str(a))
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
26 f.close()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
27
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
28 def test_log(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
29 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
30 rev0 = self.client.commit('first', addremove=True)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
31 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
32 rev1 = self.client.commit('second')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
33
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
34 revs = self.client.log()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
35 revs.reverse()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
36
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
37 self.assertTrue(len(revs) == 2)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
38 self.assertEquals(revs[1], rev1)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
39
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
40 self.assertEquals(revs[0], self.client.log('0')[0])
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
41
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
42 def test_outgoing_incoming(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
44 self.client.commit('first', addremove=True)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
45 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46 self.client.commit('second')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
48 self.client.clone(dest='bar')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
49 bar = hglib.connect('bar')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
50
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
51 self.assertEquals(self.client.log(), bar.log())
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
52 self.assertEquals(self.client.outgoing(path='bar'), bar.incoming())
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
53
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
54 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
55 rev = self.client.commit('third')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
56 out = self.client.outgoing(path='bar')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
57
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
58 self.assertEquals(len(out), 1)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
59 self.assertEquals(out[0], rev)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
60
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
61 self.assertEquals(out, bar.incoming())
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
62
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
63 def test_branch(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
64 self.assertEquals(self.client.branch(), 'default')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
65 self.append('a', 'a')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66 rev = self.client.commit('first', addremove=True)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
67 branches = self.client.branches()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
68
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
69 self.assertEquals(rev, branches[rev.branch])
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
70
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
71 def test_encoding(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
72 self.client = hglib.connect(encoding='utf-8')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
73 self.assertEquals(self.client.encoding, 'utf-8')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
74
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
75 def test_paths(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
76 open('.hg/hgrc', 'a').write('[paths]\nfoo = bar\n')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
77
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
78 # hgrc isn't watched for changes yet, have to reconnect
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
79 self.client = hglib.connect()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
80 paths = self.client.paths()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
81 self.assertEquals(len(paths), 1)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
82 self.assertEquals(paths['foo'], os.path.abspath('bar'))
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
83 self.assertEquals(self.client.paths('foo'), os.path.abspath('bar'))
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
84
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
85 def test_import(self):
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
86 patch = """
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
87 # HG changeset patch
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
88 # User test
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
89 # Date 0 0
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
90 # Node ID c103a3dec114d882c98382d684d8af798d09d857
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
91 # Parent 0000000000000000000000000000000000000000
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
92 1
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
93
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
94 diff -r 000000000000 -r c103a3dec114 a
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
95 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
96 +++ b/a Thu Jan 01 00:00:00 1970 +0000
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
97 @@ -0,0 +1,1 @@
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
98 +1
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
99 """
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
100 self.client.import_(cStringIO.StringIO(patch))
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
101 self.assertEquals(self.client.cat(['a']), '1\n')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
102
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
103 if __name__ == '__main__':
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
104 stream = cStringIO.StringIO()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
105 runner = unittest.TextTestRunner(stream=stream, verbosity=0)
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
106
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
107 # XXX fix this
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
108 module = __import__('__main__')
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
109 loader = unittest.TestLoader()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
110 ret = not runner.run(loader.loadTestsFromModule(module)).wasSuccessful()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
111 if ret:
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
112 print stream.getvalue()
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
113
79f88b4db15f Initial commit
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
114 sys.exit(ret)