TestCmd.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4')
"""
-# Copyright 2000, 2001, 2002, 2003, 2004 Steven Knight
+# Copyright 2000-2010 Steven Knight
# This module is free software, and you may redistribute it and/or modify
# it under the same terms as Python itself, so long as this copyright message
# and disclaimer are retained in their original form.
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.36.D001 2009/07/24 08:45:26 knight"
-__version__ = "0.36"
+__revision__ = "TestCmd.py 0.37.D001 2010/01/11 16:55:50 knight"
+__version__ = "0.37"
import errno
import os
-class TestCmd:
+try:
+ object
+except NameError:
+ class object:
+ pass
+
+
+
+class TestCmd(object):
"""Class TestCmd
"""
interpreter = None,
arguments = None):
if program:
- if type(program) is type('') and not os.path.isabs(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 type(program) not in [type([]), type(())]:
+ if not type(program) in [type([]), type(())]:
program = [program]
cmd = list(program)
if interpreter:
interpreter = [interpreter]
cmd = list(interpreter) + cmd
if arguments:
- if type(arguments) is type(''):
+ if type(arguments) == type(''):
arguments = string.split(arguments)
cmd.extend(arguments)
return cmd
if universal_newlines is None:
universal_newlines = self.universal_newlines
+ # On Windows, if we make stdin a pipe when we plan to send
+ # no input, and the test program exits before
+ # Popen calls msvcrt.open_osfhandle, that call will fail.
+ # So don't use a pipe for stdin if we don't need one.
+ stdin = kw.get('stdin', None)
+ if stdin is not None:
+ stdin = subprocess.PIPE
+
combine = kw.get('combine', self.combine)
if combine:
stderr_value = subprocess.STDOUT
stderr_value = subprocess.PIPE
return Popen(cmd,
- stdin=subprocess.PIPE,
+ stdin=stdin,
stdout=subprocess.PIPE,
stderr=stderr_value,
universal_newlines=universal_newlines)
if self.verbose:
sys.stderr.write("chdir(" + chdir + ")\n")
os.chdir(chdir)
- p = self.start(program, interpreter, arguments, universal_newlines)
+ p = self.start(program,
+ interpreter,
+ arguments,
+ universal_newlines,
+ stdin=stdin)
if stdin:
if is_List(stdin):
for line in stdin:
p.stdin.write(line)
else:
p.stdin.write(stdin)
- p.stdin.close()
+ p.stdin.close()
out = p.stdout.read()
if p.stderr is None:
test.must_not_be_writable('file1', ['file2', ...])
+ test.must_not_contain('file', 'banned text\n')
+
test.must_not_contain_any_line(output, lines, ['title', find])
test.must_not_exist('file1', ['file2', ...])
"""
-# Copyright 2000, 2001, 2002, 2003, 2004 Steven Knight
+# Copyright 2000-2010 Steven Knight
# This module is free software, and you may redistribute it and/or modify
# it under the same terms as Python itself, so long as this copyright message
# and disclaimer are retained in their original form.
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.36.D001 2009/07/24 08:45:26 knight"
-__version__ = "0.36"
+__revision__ = "TestCommon.py 0.37.D001 2010/01/11 16:55:50 knight"
+__version__ = "0.37"
import copy
import os
self.diff(expect, file_contents, 'contents ')
raise
+ def must_not_contain(self, file, banned, mode = 'rb'):
+ """Ensures that the specified file doesn't contain the banned text.
+ """
+ file_contents = self.read(file, mode)
+ contains = (string.find(file_contents, banned) != -1)
+ if contains:
+ print "File `%s' contains banned string." % file
+ print self.banner('Banned string ')
+ print banned
+ print self.banner('%s contents ' % file)
+ print file_contents
+ self.fail_test(contains)
+
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).
return [python] + string.split(string.strip(self.stdout()), '\n')
+ def start(self, *args, **kw):
+ """
+ Starts SCons in the test environment.
+
+ This method exists to tell Test{Cmd,Common} that we're going to
+ use standard input without forcing every .start() call in the
+ individual tests to do so explicitly.
+ """
+ if not kw.has_key('stdin'):
+ kw['stdin'] = True
+ return apply(TestCommon.start, (self,) + args, kw)
+
def wait_for(self, fname, timeout=10.0, popen=None):
"""
Waits for the specified file name to exist.