Expect¶
Expect.new¶
Creates a new Expect object.
Internal; only other Expect
methods should be calling this.
PARAMETERS ¶
- env¶:
unittest env struct or some approximation.
- meta¶:
(
ExpectMeta
) metadata about call chain and state.
Expect.new_from_env¶
Expect.new_from_env(env)
Wrapper around env
.
This is the entry point to the Truth-style assertions. Example usage: expect = expect(env) expect.that_action(action).contains_at_least_args(…)
The passed in env
object allows optional attributes to be set to
customize behavior. Usually this is helpful for testing. See _fake_env()
in truth_tests.bzl for examples.
fail
: callable that takes a failure message. If present, it will be called instead of the regularExpect.add_failure
logic.get_provider
: callable that takes 2 positional args (target and provider) and returns the found provider or fails.has_provider
: callable that takes 2 positional args (aTarget
and a [provider
]) and returnsbool
(True
if present,False
otherwise) or fails.
PARAMETERS ¶
- env¶:
unittest env struct, or some approximation. There are several attributes that override regular behavior; see above doc.
Expect.that_action¶
Expect.that_action(action)
Creates a subject for asserting Actions.
PARAMETERS ¶
- RETURNS ¶
ActionSubject
object.
Expect.that_bool¶
Expect.that_bool(value, expr=”boolean”)
Creates a subject for asserting a boolean.
PARAMETERS ¶
- value¶:
(
bool
) the bool to check.- expr¶:
(default
"boolean"
) (str
) the starting “value of” expression to report in errors.
- RETURNS ¶
BoolSubject
object.
Expect.that_collection¶
Expect.that_collection(collection, expr=”collection”, kwargs)
Creates a subject for asserting collections.
PARAMETERS ¶
- collection¶:
The collection (list or depset) to assert.
- expr¶:
(default
"collection"
) (str
) the starting “value of” expression to report in errors.- kwargs¶:
Additional kwargs to pass onto CollectionSubject.new
- RETURNS ¶
CollectionSubject
object.
Expect.that_depset_of_files¶
Expect.that_depset_of_files(depset_files)
Creates a subject for asserting a depset of files.
Method: Expect.that_depset_of_files
PARAMETERS ¶
- RETURNS ¶
DepsetFileSubject
object.
Expect.that_dict¶
Expect.that_dict(mapping, meta=None)
Creates a subject for asserting a dict.
Method: Expect.that_dict
PARAMETERS ¶
- mapping¶:
(
dict
) the values to assert on- meta¶:
(default
None
) (ExpectMeta
) optional custom call chain information to use instead
- RETURNS ¶
DictSubject
object.
Expect.that_file¶
Expect.that_file(file, meta=None)
Creates a subject for asserting a file.
Method: Expect.that_file
PARAMETERS ¶
- file¶:
(
File
) the value to assert.- meta¶:
(default
None
) (ExpectMeta
) optional custom call chain information to use instead
- RETURNS ¶
FileSubject
object.
Expect.that_int¶
Expect.that_int(value, expr=”integer”)
Creates a subject for asserting an int
.
Method: Expect.that_int
PARAMETERS ¶
- value¶:
([
int
]) the value to check against.- expr¶:
(default
"integer"
) (str
) the starting “value of” expression to report in errors.
- RETURNS ¶
IntSubject
object.
Expect.that_str¶
Expect.that_str(value)
Creates a subject for asserting a str
.
PARAMETERS ¶
- RETURNS ¶
StrSubject
object.
Expect.that_struct¶
Expect.that_struct(value, attrs, expr=”struct”)
Creates a subject for asserting a struct
.
PARAMETERS ¶
- value¶:
(
struct
) the value to check against.- attrs¶:
(
dict
ofstr
to [callable
]) the functions to convert attributes to subjects. The keys are attribute names that must exist onactual
. The values are functions with the signaturedef factory(value, *, meta)
, wherevalue
is the actual attribute value of the struct, andmeta
is anExpectMeta
object.- expr¶:
(default
"struct"
) (str
) The starting “value of” expression to report in errors.
- RETURNS ¶
StructSubject
object.
Expect.that_target¶
Expect.that_target(target)
Creates a subject for asserting a Target
.
This adds the following parameters to ExpectMeta.format_str
:
{package}: The target’s package, e.g. “foo/bar” from “//foo/bar:baz”
{name}: The target’s base name, e.g., “baz” from “//foo/bar:baz”
PARAMETERS ¶
- RETURNS ¶
TargetSubject
object.
Expect.that_value¶
Expect.that_value(value, factory, expr=”value”)
Creates a subject for asserting an arbitrary value of a custom type.
PARAMETERS ¶
- value¶:
(
struct
) the value to check against.- factory¶:
A subject factory (a function that takes value and meta). Eg. subjects.collection
- expr¶:
(default
"value"
) (str
) The starting “value of” expression to report in errors.
- RETURNS ¶
A subject corresponding to the type returned by the factory.
Expect.where¶
Expect.where(details)
Add additional information about the assertion.
This is useful for attaching information that isn’t part of the call chain or some reason. Example usage:
expect(env).where(platform=ctx.attr.platform).that_str(...)
Would include “platform: {ctx.attr.platform}” in failure messages.
PARAMETERS ¶