import TestCmd
test = TestCmd.TestCmd()
-There are a bunch of keyword arguments that you can use at instantiation
-time:
+There are a bunch of keyword arguments available at instantiation:
test = TestCmd.TestCmd(description = 'string',
program = 'program_or_script_to_test',
match = default_match_function,
combine = Boolean)
-There are a bunch of methods that let you do a bunch of different
-things. Here is an overview of them:
+There are a bunch of methods that let you do different things:
test.verbose_set(1)
test.cleanup(condition)
+ test.command_args(program = 'program_or_script_to_run',
+ interpreter = 'script_interpreter',
+ arguments = 'arguments to pass to program')
+
test.run(program = 'program_or_script_to_run',
interpreter = 'script_interpreter',
arguments = 'arguments to pass to program',
chdir = 'directory_to_chdir_to',
stdin = 'input to feed to the program\n')
+ universal_newlines = True)
+
+ p = test.start(program = 'program_or_script_to_run',
+ interpreter = 'script_interpreter',
+ arguments = 'arguments to pass to program',
+ universal_newlines = None)
+
+ test.finish(self, p)
test.pass_test()
test.pass_test(condition)
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.34.D001 2008/12/28 23:12:34 knight"
-__version__ = "0.34"
+__revision__ = "TestCmd.py 0.35.D001 2009/02/08 07:10:39 knight"
+__version__ = "0.35"
import errno
import os
path = os.path.join(self.workdir, path)
return path
+ def chmod(self, path, mode):
+ """Changes permissions on the specified file or directory
+ path name."""
+ path = self.canonicalize(path)
+ os.chmod(path, mode)
+
def cleanup(self, condition = None):
"""Removes any temporary working directories for the specified
TestCmd environment. If the environment variable PRESERVE was
except (AttributeError, ValueError):
pass
- def chmod(self, path, mode):
- """Changes permissions on the specified file or directory
- path name."""
- path = self.canonicalize(path)
- os.chmod(path, mode)
+ def command_args(self, program = None,
+ interpreter = None,
+ arguments = None):
+ if program:
+ if type(program) == type('') and not os.path.isabs(program):
+ program = os.path.join(self._cwd, program)
+ else:
+ program = self.program
+ if not interpreter:
+ interpreter = self.interpreter
+ if not type(program) in [type([]), type(())]:
+ program = [program]
+ cmd = list(program)
+ if interpreter:
+ if not type(interpreter) in [type([]), type(())]:
+ interpreter = [interpreter]
+ cmd = list(interpreter) + cmd
+ if arguments:
+ if type(arguments) == type(''):
+ arguments = string.split(arguments)
+ cmd.extend(arguments)
+ return cmd
def description_set(self, description):
"""Set the description of the functionality being tested.
The specified program will have the original directory
prepended unless it is enclosed in a [list].
"""
- if program:
- if type(program) == type('') and not os.path.isabs(program):
- program = os.path.join(self._cwd, program)
- else:
- program = self.program
- if not interpreter:
- interpreter = self.interpreter
- if not type(program) in [type([]), type(())]:
- program = [program]
- cmd = list(program)
- if interpreter:
- if not type(interpreter) in [type([]), type(())]:
- interpreter = [interpreter]
- cmd = list(interpreter) + cmd
- if arguments:
- if type(arguments) == type(''):
- arguments = string.split(arguments)
- cmd.extend(arguments)
+ cmd = self.command_args(program, interpreter, arguments)
cmd_string = string.join(map(self.escape, cmd), ' ')
if self.verbose:
sys.stderr.write(cmd_string + "\n")
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.34.D001 2008/12/28 23:12:34 knight"
-__version__ = "0.34"
+__revision__ = "TestCommon.py 0.35.D001 2009/02/08 07:10:39 knight"
+__version__ = "0.35"
import copy
import os
self.fail_test(not contains)
def must_contain_all_lines(self, output, lines, title=None, find=None):
+ """Ensures that the specified output string (first argument)
+ contains all of the specified lines (second argument).
+
+ An optional third argument can be used to describe the type
+ of output being searched, and only shows up in failure output.
+
+ An optional fourth argument can be used to supply a different
+ function, of the form "find(line, output), to use when searching
+ for lines in the output.
+ """
if find is None:
find = lambda o, l: string.find(o, l) != -1
missing = []
sys.stdout.write("Missing expected lines from %s:\n" % title)
for line in missing:
sys.stdout.write(' ' + repr(line) + '\n')
- separator = title + ' ' + '=' * (78 - len(title) - 1)
- sys.stdout.write(separator + '\n')
+ sys.stdout.write(self.banner(title + ' '))
sys.stdout.write(output)
self.fail_test()
def must_contain_any_line(self, output, lines, title=None, find=None):
+ """Ensures that the specified output string (first argument)
+ contains at least one of the specified lines (second argument).
+
+ An optional third argument can be used to describe the type
+ of output being searched, and only shows up in failure output.
+
+ An optional fourth argument can be used to supply a different
+ function, of the form "find(line, output), to use when searching
+ for lines in the output.
+ """
if find is None:
find = lambda o, l: string.find(o, l) != -1
for line in lines:
sys.stdout.write("Missing any expected line from %s:\n" % title)
for line in lines:
sys.stdout.write(' ' + repr(line) + '\n')
- separator = title + ' ' + '=' * (78 - len(title) - 1)
- sys.stdout.write(separator + '\n')
+ sys.stdout.write(self.banner(title + ' '))
sys.stdout.write(output)
self.fail_test()
raise
def must_not_contain_any_line(self, output, lines, title=None, find=None):
+ """Ensures that the specified output string (first argument)
+ does not contain any of the specified lines (second argument).
+
+ An optional third argument can be used to describe the type
+ of output being searched, and only shows up in failure output.
+
+ An optional fourth argument can be used to supply a different
+ function, of the form "find(line, output), to use when searching
+ for lines in the output.
+ """
if find is None:
find = lambda o, l: string.find(o, l) != -1
unexpected = []
sys.stdout.write("Unexpected lines in %s:\n" % title)
for line in unexpected:
sys.stdout.write(' ' + repr(line) + '\n')
- separator = title + ' ' + '=' * (78 - len(title) - 1)
- sys.stdout.write(separator + '\n')
+ sys.stdout.write(self.banner(title + ' '))
sys.stdout.write(output)
self.fail_test()
- def must_not_contain_lines(self, lines, output, title=None, find=None):
- return self.must_not_contain_any_line(output, lines, title, find)
+ def must_not_contain_lines(self, lines, output, title=None):
+ return self.must_not_contain_any_line(output, lines, title)
def must_not_exist(self, *files):
"""Ensures that the specified file(s) must not exist.
print self.stderr()
except IndexError:
pass
+ cmd_args = self.command_args(program, interpreter, arguments)
+ sys.stderr.write('Exception trying to execute: %s\n' % cmd_args)
raise e
def finish(self, popen, stdout = None, stderr = '', status = 0, **kw):