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