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