Capture
- class aws_cdk.assertions.Capture(pattern=None)
Bases:
Matcher
Capture values while matching templates.
Using an instance of this class within a Matcher will capture the matching value. The
as*()
APIs on the instance can be used to get the captured value.- ExampleMetadata:
infused
Example:
# Given a template - # { # "Resources": { # "MyBar": { # "Type": "Foo::Bar", # "Properties": { # "Fred": "Flob", # } # }, # "MyBaz": { # "Type": "Foo::Bar", # "Properties": { # "Fred": "Quib", # } # } # } # } fred_capture = Capture() template.has_resource_properties("Foo::Bar", { "Fred": fred_capture }) fred_capture.as_string() # returns "Flob" fred_capture.next() # returns true fred_capture.as_string()
Initialize a new capture.
- Parameters:
pattern (
Optional
[Any
]) – a nested pattern or Matcher. If a nested pattern is providedobjectLike()
matching is applied.
Methods
- as_array()
Retrieve the captured value as an array.
An error is generated if no value is captured or if the value is not an array.
- Return type:
List
[Any
]
- as_boolean()
Retrieve the captured value as a boolean.
An error is generated if no value is captured or if the value is not a boolean.
- Return type:
bool
- as_number()
Retrieve the captured value as a number.
An error is generated if no value is captured or if the value is not a number.
- Return type:
Union
[int
,float
]
- as_object()
Retrieve the captured value as a JSON object.
An error is generated if no value is captured or if the value is not an object.
- Return type:
Mapping
[str
,Any
]
- as_string()
Retrieve the captured value as a string.
An error is generated if no value is captured or if the value is not a string.
- Return type:
str
- next()
When multiple results are captured, move the iterator to the next result.
- Return type:
bool
- Returns:
true if another capture is present, false otherwise
- test(actual)
Test whether a target matches the provided pattern.
Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.
- Parameters:
actual (
Any
) –- Return type:
Attributes
- name
A name for the matcher.
This is collected as part of the result and may be presented to the user.
Static Methods
- classmethod is_matcher(x)
Check whether the provided object is a subtype of the
IMatcher
.- Parameters:
x (
Any
) –- Return type:
bool