[PATCH 1 of 3 hglib] tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara
idankk86 at gmail.com
Fri Sep 9 11:10:44 CDT 2011
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1315245089 -10800
# Node ID 730c42743ba31689c0c5772da7515c4c9184d334
# Parent 358fd5c84270a721931282a7264cbb5fc016e090
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
diff --git a/tests/__init__.py b/tests/__init__.py
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -18,4 +18,5 @@
os.environ["HGTMP"] = os.path.realpath(tmpdir)
def tearDown(self):
+ os.chdir('..')
shutil.rmtree(os.environ["HGTMP"])
diff --git a/tests/common.py b/tests/common.py
--- a/tests/common.py
+++ b/tests/common.py
@@ -3,11 +3,24 @@
import hglib
+def resultappender(list):
+ def decorator(f):
+ def decorated(*args, **kwargs):
+ result = f(*args, **kwargs)
+ list.append(result)
+ return result
+ return decorated
+ return decorator
+
class basetest(unittest.TestCase):
def setUp(self):
self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
os.path.join(os.environ["HGTMP"], self.__class__.__name__)
+ self.clients = []
+ self._oldopen = hglib.open
+ hglib.open = resultappender(self.clients)(hglib.open)
+
os.mkdir(self._testtmp)
os.chdir(self._testtmp)
# until we can run norepo commands in the cmdserver
@@ -15,6 +28,13 @@
self.client = hglib.open()
def tearDown(self):
+ # on Windows we cannot rmtree before closing all instances because of used
+ # files
+ hglib.open = self._oldopen
+ for client in self.clients:
+ if client.server is not None:
+ client.close()
+ os.chdir('..')
try:
shutil.rmtree(self._testtmp)
except AttributeError:
More information about the Mercurial-devel
mailing list