From 4cd72bc7efc04fddf39b208b3d0bb7293bc904d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 22 Aug 2009 14:31:51 +0200 Subject: add doctest for Command.__call__() --- gbp/command_wrappers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gbp') diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index 8f6f7fe4..b73549b3 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -1,6 +1,6 @@ # vim: set fileencoding=utf-8 : # -# (C) 2007 Guido Guenther +# (C) 2007,2009 Guido Guenther """ Simple class wrappers for the various external commands needed by git-buildpackage and friends @@ -54,7 +54,7 @@ class Command(object): run self.cmd adding args as additional arguments be verbose about errors and encode them in the return value, don't pass - on exceptons + on exceptons """ try: retcode = self.__call(args) @@ -72,7 +72,13 @@ class Command(object): def __call__(self, args=[]): """run the command, convert all errors into CommandExecFailed, assumes that the lower levels printed an error message - only usefull if you - only expect 0 as result""" + only expect 0 as result + >>> Command("/bin/true")(["foo", "bar"]) + >>> Command("/foo/bar")() + Traceback (most recent call last): + ... + CommandExecFailed + """ if self.__run(args): raise CommandExecFailed @@ -85,7 +91,6 @@ class Command(object): return ret - class RunAtCommand(Command): """Run a command in a specific directory""" def __call__(self, dir='.', *args): @@ -132,6 +137,7 @@ class UnpackTarArchive(Command): Command.__init__(self, 'tar', exclude + ['-C', dir, decompress, '-xf', archive ]) self.run_error = 'Couldn\'t unpack "%s"' % self.archive + class RepackTarArchive(Command): """Wrap tar to Repack a gzipped tar archive""" def __init__(self, archive, dir, dest): @@ -146,6 +152,7 @@ class RepackTarArchive(Command): Command.__init__(self, 'tar', ['-C', dir, compress, '-cf', archive, dest]) self.run_error = 'Couldn\'t repack "%s"' % self.archive + class RemoveTree(Command): "Wrap rm to remove a whole directory tree" def __init__(self, tree): -- cgit v1.2.3