-
Notifications
You must be signed in to change notification settings - Fork 54
/
common.py
49 lines (42 loc) · 1.46 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os, sys, tempfile, shutil
import unittest
import hglib
from hglib import client
def resultappender(list):
def decorator(f):
def decorated(*args, **kwargs):
list.append(args[0])
return f(*args, **kwargs)
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.client.hgclient.open
# hglib.open = resultappender(self.clients)(hglib.open)
c = hglib.client.hgclient
c.open = resultappender(self.clients)(c.open)
os.mkdir(self._testtmp)
os.chdir(self._testtmp)
# until we can run norepo commands in the cmdserver
os.system('hg init')
self.client = hglib.open()
def tearDown(self):
# on Windows we cannot rmtree before closing all instances
# because of used files
hglib.client.hgclient.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:
pass # if our setUp was overriden
def append(self, path, *args):
f = open(path, 'ab')
for a in args:
f.write(a.encode('latin-1'))
f.close()