Mercurial > public > mercurial-scm > python-hglib
comparison tests/common.py @ 101:d1a42c1d0b61
tests: hook into hgclient.open for closing open cmdservers
So we ensure proper cleanup and cover all top level functions.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Wed, 18 Jan 2012 00:39:24 +0200 |
parents | a0328b08e028 |
children | 1b47146a4a2c |
comparison
equal
deleted
inserted
replaced
100:dd63d69a5ebf | 101:d1a42c1d0b61 |
---|---|
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 from hglib import client | |
5 | 6 |
6 def resultappender(list): | 7 def resultappender(list): |
7 def decorator(f): | 8 def decorator(f): |
8 def decorated(*args, **kwargs): | 9 def decorated(*args, **kwargs): |
9 result = f(*args, **kwargs) | 10 list.append(args[0]) |
10 list.append(result) | 11 return f(*args, **kwargs) |
11 return result | |
12 return decorated | 12 return decorated |
13 return decorator | 13 return decorator |
14 | 14 |
15 class basetest(unittest.TestCase): | 15 class basetest(unittest.TestCase): |
16 def setUp(self): | 16 def setUp(self): |
17 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ | 17 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ |
18 os.path.join(os.environ["HGTMP"], self.__class__.__name__) | 18 os.path.join(os.environ["HGTMP"], self.__class__.__name__) |
19 | 19 |
20 self.clients = [] | 20 self.clients = [] |
21 self._oldopen = hglib.open | 21 self._oldopen = hglib.client.hgclient.open |
22 hglib.open = resultappender(self.clients)(hglib.open) | 22 # hglib.open = resultappender(self.clients)(hglib.open) |
23 hglib.client.hgclient.open = resultappender(self.clients)(hglib.client.hgclient.open) | |
23 | 24 |
24 os.mkdir(self._testtmp) | 25 os.mkdir(self._testtmp) |
25 os.chdir(self._testtmp) | 26 os.chdir(self._testtmp) |
26 # until we can run norepo commands in the cmdserver | 27 # until we can run norepo commands in the cmdserver |
27 os.system('hg init') | 28 os.system('hg init') |
28 self.client = hglib.open() | 29 self.client = hglib.open() |
29 | 30 |
30 def tearDown(self): | 31 def tearDown(self): |
31 # on Windows we cannot rmtree before closing all instances because of used | 32 # on Windows we cannot rmtree before closing all instances because of used |
32 # files | 33 # files |
33 hglib.open = self._oldopen | 34 hglib.client.hgclient.open = self._oldopen |
34 for client in self.clients: | 35 for client in self.clients: |
35 if client.server is not None: | 36 if client.server is not None: |
36 client.close() | 37 client.close() |
37 os.chdir('..') | 38 os.chdir('..') |
38 try: | 39 try: |