annotate tests/common.py @ 83:c41442cb355d 0.1

.hgignore: add some setup.py junk
author Matt Mackall <mpm@selenic.com>
date Thu, 10 Nov 2011 17:15:52 -0600
parents a0328b08e028
children d1a42c1d0b61
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
1 import os, sys, tempfile, shutil
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
2 import unittest
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
3
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4 import hglib
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
6 def resultappender(list):
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
7 def decorator(f):
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
8 def decorated(*args, **kwargs):
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
9 result = f(*args, **kwargs)
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
10 list.append(result)
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
11 return result
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
12 return decorated
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
13 return decorator
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
14
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
15 class basetest(unittest.TestCase):
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16 def setUp(self):
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
17 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
18 os.path.join(os.environ["HGTMP"], self.__class__.__name__)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
19
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
20 self.clients = []
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
21 self._oldopen = hglib.open
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
22 hglib.open = resultappender(self.clients)(hglib.open)
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
23
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
24 os.mkdir(self._testtmp)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
25 os.chdir(self._testtmp)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
26 # until we can run norepo commands in the cmdserver
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
27 os.system('hg init')
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
28 self.client = hglib.open()
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
29
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
30 def tearDown(self):
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
31 # on Windows we cannot rmtree before closing all instances because of used
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
32 # files
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
33 hglib.open = self._oldopen
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
34 for client in self.clients:
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
35 if client.server is not None:
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
36 client.close()
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
37 os.chdir('..')
58
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
38 try:
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
39 shutil.rmtree(self._testtmp)
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
40 except AttributeError:
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
41 pass # if our setUp was overriden
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
42
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43 def append(self, path, *args):
68
a0328b08e028 tests: open files in binary mode so new lines aren't converted
Idan Kamara <idankk86@gmail.com>
parents: 67
diff changeset
44 f = open(path, 'ab')
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
45 for a in args:
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46 f.write(str(a))
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47 f.close()