Mercurial > python-hglib
comparison tests/common.py @ 67:730c42743ba3
tests: cleanup on test finish so Windows doesn't complain about used files
- chdir out of the test dir before rmtree
- cache instances of hgclient and close them explicitly on tearDown before
rmtree
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Mon, 05 Sep 2011 20:51:29 +0300 |
parents | 3d413c54e048 |
children | a0328b08e028 |
comparison
equal
deleted
inserted
replaced
66:358fd5c84270 | 67:730c42743ba3 |
---|---|
1 import os, sys, tempfile, shutil | 1 import os, sys, tempfile, shutil |
2 import unittest | 2 import unittest |
3 | 3 |
4 import hglib | 4 import hglib |
5 | 5 |
6 def resultappender(list): | |
7 def decorator(f): | |
8 def decorated(*args, **kwargs): | |
9 result = f(*args, **kwargs) | |
10 list.append(result) | |
11 return result | |
12 return decorated | |
13 return decorator | |
14 | |
6 class basetest(unittest.TestCase): | 15 class basetest(unittest.TestCase): |
7 def setUp(self): | 16 def setUp(self): |
8 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ | 17 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ |
9 os.path.join(os.environ["HGTMP"], self.__class__.__name__) | 18 os.path.join(os.environ["HGTMP"], self.__class__.__name__) |
19 | |
20 self.clients = [] | |
21 self._oldopen = hglib.open | |
22 hglib.open = resultappender(self.clients)(hglib.open) | |
10 | 23 |
11 os.mkdir(self._testtmp) | 24 os.mkdir(self._testtmp) |
12 os.chdir(self._testtmp) | 25 os.chdir(self._testtmp) |
13 # until we can run norepo commands in the cmdserver | 26 # until we can run norepo commands in the cmdserver |
14 os.system('hg init') | 27 os.system('hg init') |
15 self.client = hglib.open() | 28 self.client = hglib.open() |
16 | 29 |
17 def tearDown(self): | 30 def tearDown(self): |
31 # on Windows we cannot rmtree before closing all instances because of used | |
32 # files | |
33 hglib.open = self._oldopen | |
34 for client in self.clients: | |
35 if client.server is not None: | |
36 client.close() | |
37 os.chdir('..') | |
18 try: | 38 try: |
19 shutil.rmtree(self._testtmp) | 39 shutil.rmtree(self._testtmp) |
20 except AttributeError: | 40 except AttributeError: |
21 pass # if our setUp was overriden | 41 pass # if our setUp was overriden |
22 | 42 |