From 85d002c81545116bae49bd7e433bc548b41d218e Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 14 Jul 2002 16:24:09 +0000 Subject: [PATCH] More test cases. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/Archive@1684 66de3db3-b00d-0410-b41b-f4738ad19bea --- support.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/support.py b/support.py index 483fa15..9c671be 100644 --- a/support.py +++ b/support.py @@ -78,7 +78,7 @@ def pipe_through_command(command, src, dst): pid, status = os.waitpid(child, 0) if errors: - raise ChildError('Errors from command %s:\n%s' % (command, errors)) + raise ChildError("Errors from command '%s':\n%s" % (command, errors)) if status != 0: raise ChildError("Command '%s' returned an error code!" % command) @@ -90,6 +90,10 @@ def pipe_through_command(command, src, dst): def test(): "Check that this module works." + def show(): + error = sys.exc_info()[1] + print "(error reported was '%s')" % error + print "Test escape()..." assert escape(''' a test ''') == ' a test ' @@ -107,16 +111,19 @@ def test(): file.seek(0) assert file.read() == 'Hello World' - print "Test pipe_through_command()..." + print "Test pipe_through_command():" - print " invalid command..." + print "Try an invalid command..." try: pipe_through_command('bad_command_1234', None, None) assert 0 except ChildError: - pass + show() else: assert 0 + + print "Try a valid command..." + pipe_through_command('exit 0', None, None) print "Writing to a non-fileno stream..." from cStringIO import StringIO @@ -124,7 +131,7 @@ def test(): pipe_through_command('echo Hello', None, a) assert a.getvalue() == 'Hello\n' - print "Reading from a stream..." + print "Reading from a stream to a StringIO..." file.seek(1) pipe_through_command('cat', file, a) assert a.getvalue() == 'Hello\nello World' @@ -136,11 +143,21 @@ def test(): file.seek(0) assert file.read() == 'Foo\n' + print "Read and write fileno streams..." + src = Tmp() + src.write('123') + src.seek(0) + file.seek(0) + file.truncate(0) + pipe_through_command('cat', src, file) + file.seek(0) + assert file.read() == '123' + print "Detect non-zero exit value..." try: pipe_through_command('exit 1', None, None) except ChildError: - pass + show() else: assert 0 @@ -148,7 +165,7 @@ def test(): try: pipe_through_command('echo one >&2; sleep 2; echo two >&2', None, None) except ChildError: - pass + show() else: assert 0 -- 2.11.4.GIT