Caution

Buildbot no longer supports Python 2.7 on the Buildbot master.

2.5.25.1. Worker command expectations

TestBuildStepMixin is used to test steps and accepts command expectations to its expect_commands method. These command expectations are instances of classes listed in this page.

In all cases the arguments used to construct the expectation is what is expected to receive from the step under test. The methods called on the command are used to build a list of effects that the step will observe.

class buildbot.test.steps.Expect

This class is the base class of all command expectation classes. It must not be instantiated by the user. It provides methods that are common to all command expectations.

exit(code)
Parameters:

code (int) – Exit code

Specifies command exit code sent to the step. In most cases 0 signify success, other values signify failure.

stdout(output)
Parameters:

output – stdout output to send to the step. Must be an instance of bytes or str.

Specifies stdout stream in the stdio log that is sent by the command to the step.

stderr(output)
Parameters:

output – stderr output to send to the step. Must be an instance of bytes or str.

Specifies stderr stream in the stdio log that is sent by the command to the step.

log(name, **streams)
Parameters:
  • name (str) – The name of the log.

  • streams (kwargs) – The log streams of the log streams. The most common are stdout and stderr. The values must be instances of bytes or str.

Specifies logs sent by the command to the step.

For stdio log and stdout stream use the stdout() function.

For stdio log and stderr stream use the stderr() function.

error(error)
Parameters:

error – An instance of an exception to throw when running the command.

Throws an exception when running the command. This is often used to simulate broken connection by throwing in an instance of twisted.internet.error.ConnectionLost.

ExpectShell

class buildbot.test.steps.ExpectShell(Expect)

This class represents a shell command sent to the worker.

Usually the stdout log produced by the command is specified by the .stdout method, the stderr log is specified by the .stderr method and the exit code is specified by the .exit method.

ExpectShell(workdir='myworkdir', command=["my-test-command", "arg1", "arg2"])
.stdout(b'my sample output')
.exit(0)
__init__(workdir, command, env=None, want_stdout=1, want_stderr=1, initial_stdin=None, timeout=20 * 60, max_time=None, sigterm_time=None, logfiles=None, use_pty=None, log_environ=True, interrupt_signal=None)

Initializes the expectation.

ExpectStat

class buildbot.test.steps.ExpectStat(Expect)

This class represents a stat command sent to the worker.

Tests usually indicate the existence of the file by calling the .exit method.

__init__(file, workdir=None, log_environ=None)

Initializes the expectation.

stat(mode, inode=99, dev=99, nlink=1, uid=0, gid=0, size=99, atime=0, mtime=0, ctime=0)

Specifies os.stat result that is sent back to the step.

In most cases it’s more convenient to use stat_file or stat_dir.

stat_file(mode=0, size=99, atime=0, mtime=0, ctime=0)
Parameters:

mode (int) – Additional mode bits to set

Specifies os.stat result of a regular file.

stat_dir(mode=0, size=99, atime=0, mtime=0, ctime=0)
Parameters:

mode (int) – Additional mode bits to set

Specifies os.stat result of a directory.

ExpectUploadFile

class buildbot.test.steps.ExpectUploadFile(Expect)

This class represents a uploadFile command sent to the worker.

__init__(blocksize=None, maxsize=None, workersrc=None, workdir=None, writer=None, keepstamp=None, slavesrc=None, interrupted=False)

Initializes the expectation.

upload_string(string, error=None)
Parameters:
  • string (str) – The data of the file to sent to the step.

  • error (object) – An optional instance of an exception to raise to simulate failure to transfer data.

Specifies the data to send to the step.

ExpectDownloadFile

class buildbot.test.steps.ExpectDownloadFile(Expect)

This class represents a downloadFile command sent to the worker. Tests usually check what the step attempts to send to the worker by calling .download_string and checking what data the supplied callable receives.

__init__(blocksize=None, maxsize=None, workerdest=None, workdir=None, reader=None, mode=None, interrupted=False, slavesrc=None, slavedest=None)

Initializes the expectation.

download_string(dest_callable, size=1000)
Parameters:
  • dest_callable (callable) – A callable to call with the data that is being sent from the step.

  • size (int) – The size of the data to read

Specifies the callable to store the data that the step wants the worker to download.

ExpectMkdir

class buildbot.test.steps.ExpectMkdir(Expect)

This class represents a mkdir command sent to the worker.

__init__(dir=None, log_environ=None))

Initializes the expectation.

ExpectRmdir

class buildbot.test.steps.ExpectRmdir(Expect)

This class represents a rmdir command sent to the worker.

__init__(dir=None, log_environ=None, timeout=None, path=None)

Initializes the expectation.

ExpectCpdir

class buildbot.test.steps.ExpectCpdir(Expect)

This class represents a cpdir command sent to the worker.

__init__(fromdir=None, todir=None, log_environ=None, timeout=None, max_time=None)

Initializes the expectation.

ExpectRmfile

class buildbot.test.steps.ExpectRmfile(Expect)

This class represents a rmfile command sent to the worker.

__init__(path=None, log_environ=None)

Initializes the expectation.

ExpectGlob

class buildbot.test.steps.ExpectGlob(Expect)

This class represents a mkdir command sent to the worker.

__init__(path=None, log_environ=None)

Initializes the expectation.

files(files=None)
Parameters:

files (list) – An optional list of returned files.

Specifies the list of files returned to the step.

ExpectListdir

class buildbot.test.steps.ExpectListdir(Expect)

This class represents a mkdir command sent to the worker.

__init__(dir=None):

Initializes the expectation.

files(files=None)
Parameters:

files (list) – An optional list of returned files.

Specifies the list of files returned to the step.