35
35
from bzrlib.selftest import TestUtil
36
36
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
37
37
from bzrlib.selftest.treeshape import build_tree_contents
38
from bzrlib.errors import BzrError
39
40
MODULES_TO_TEST = []
40
41
MODULES_TO_DOCTEST = []
251
252
self._cleanups.append(callable)
253
254
def _cleanEnvironment(self):
254
self.oldenv = os.environ.get('HOME', None)
255
os.environ['HOME'] = os.getcwd()
256
self.bzr_email = os.environ.get('BZREMAIL')
257
if self.bzr_email is not None:
258
del os.environ['BZREMAIL']
259
self.email = os.environ.get('EMAIL')
260
if self.email is not None:
261
del os.environ['EMAIL']
257
'APPDATA': os.getcwd(),
262
262
self.addCleanup(self._restoreEnvironment)
263
for name, value in new_env.iteritems():
264
self._captureVar(name, value)
267
def _captureVar(self, name, newvalue):
268
"""Set an environment variable, preparing it to be reset when finished."""
269
self.__old_env[name] = os.environ.get(name, None)
271
if name in os.environ:
274
os.environ[name] = newvalue
277
def _restoreVar(name, value):
279
if name in os.environ:
282
os.environ[name] = value
264
284
def _restoreEnvironment(self):
265
os.environ['HOME'] = self.oldenv
266
if os.environ.get('BZREMAIL') is not None:
267
del os.environ['BZREMAIL']
268
if self.bzr_email is not None:
269
os.environ['BZREMAIL'] = self.bzr_email
270
if os.environ.get('EMAIL') is not None:
271
del os.environ['EMAIL']
272
if self.email is not None:
273
os.environ['EMAIL'] = self.email
285
for name, value in self.__old_env.iteritems():
286
self._restoreVar(name, value)
275
288
def tearDown(self):
276
289
self._runCleanups()
471
484
os.chdir(_currentdir)
472
485
self.addCleanup(_leaveDirectory)
474
def build_tree(self, shape):
487
def build_tree(self, shape, line_endings='native'):
475
488
"""Build a test tree according to a pattern.
477
490
shape is a sequence of file specifications. If the final
478
491
character is '/', a directory is created.
480
493
This doesn't add anything to a branch.
494
:param line_endings: Either 'binary' or 'native'
495
in binary mode, exact contents are written
496
in native mode, the line endings match the
497
default platform endings.
482
499
# XXX: It's OK to just create them using forward slashes on windows?
483
500
for name in shape:
485
502
if name[-1] == '/':
486
503
os.mkdir(name[:-1])
505
if line_endings == 'binary':
507
elif line_endings == 'native':
510
raise BzrError('Invalid line ending request %r' % (line_endings,))
489
511
print >>f, "contents of", name