271
270
os.chdir(self._currentdir)
272
271
super(TestCaseInTempDir, self).tearDown()
274
def _formcmd(self, cmd):
275
if isinstance(cmd, basestring):
278
cmd[0] = self.BZRPATH
279
if self.OVERRIDE_PYTHON:
280
cmd.insert(0, self.OVERRIDE_PYTHON)
281
self.log('$ %r' % cmd)
284
def runcmd(self, cmd, retcode=0):
285
"""Run one command and check the return code.
287
Returns a tuple of (stdout,stderr) strings.
289
If a single string is based, it is split into words.
290
For commands that are not simple space-separated words, please
291
pass a list instead."""
292
warn('TestBase.runcmd is deprecated', stacklevel=2)
293
cmd = self._formcmd(cmd)
294
self.log('$ ' + ' '.join(cmd))
295
actual_retcode = subprocess.call(cmd, stdout=self._log_file,
296
stderr=self._log_file)
297
if retcode != actual_retcode:
298
raise CommandFailed("test failed: %r returned %d, expected %d"
299
% (cmd, actual_retcode, retcode))
301
def backtick(self, cmd, retcode=0):
302
"""Run a command and return its output"""
303
warn('TestBase.backtick is deprecated', stacklevel=2)
304
cmd = self._formcmd(cmd)
305
child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=self._log_file)
306
outd, errd = child.communicate()
308
actual_retcode = child.wait()
310
outd = outd.replace('\r', '')
312
if retcode != actual_retcode:
313
raise CommandFailed("test failed: %r returned %d, expected %d"
314
% (cmd, actual_retcode, retcode))
320
274
def build_tree(self, shape):
321
275
"""Build a test tree according to a pattern.