scripttest
– test command-line scripts¶
Helpers for testing command-line scripts
Module Contents¶
-
class
scripttest.
TestFileEnvironment
(base_path=None, template_path=None, environ=None, cwd=None, start_clear=True, ignore_paths=None, ignore_hidden=True, capture_temp=False, assert_no_temp=False, split_cmd=True)¶ This represents an environment in which files will be written, and scripts will be run.
Objects that are returned¶
These objects are returned when you use env.run(...)
. The
ProcResult object is returned, and it has .files_updated
,
.files_created
, and .files_deleted
which are dictionaries of
FoundFile and FoundDir. The files in .files_deleted
represent
the pre-deletion state of the file; the other files represent the
state of the files after the command is run.
and.files_deleted
. These objects dictionary
-
class
scripttest.
ProcResult
(test_env, args, stdin, stdout, stderr, returncode, files_before, files_after)¶ Represents the results of running a command in TestFileEnvironment.
Attributes to pay particular attention to:
-
class
scripttest.
FoundFile
(base_path, path)¶ Represents a single file found as the result of a command.
Has attributes:
path
:- The path of the file, relative to the
base_path
full
:- The full path
bytes
:- The contents of the file.
stat
:- The results of
os.stat
. Alsomtime
andsize
contain the.st_mtime
and.st_size
of the stat. mtime
:- The modification time of the file.
size
:- The size (in bytes) of the file.
You may use the
in
operator with these objects (tested against the contents of the file), and the.mustcontain()
method.
-
class
scripttest.
FoundDir
(base_path, path)¶ Represents a directory created by a command.