API Reference¶
The “brunns.matchers” package¶
The “brunns.matchers.bytestring” module¶
- class brunns.matchers.bytestring.ContainsBytestring(bytestring)[source]¶
Matches if object is a bytestring containing a given bytestring.
- Parameters:
bytestring (
bytes) – The string to search for.
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
The “brunns.matchers.data” module¶
- class brunns.matchers.data.JsonMatching(matcher)[source]¶
Matches string containing JSON data.
- Parameters:
matcher (
str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None|Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None]) – Value to match against deserialised JSON.
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- brunns.matchers.data.json_matching(matcher)[source]¶
Matches string containing JSON data.
- Parameters:
matcher (
Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None] |str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None) – Value to match against deserialised JSON.- Return type:
The “brunns.matchers.datetime” module¶
- class brunns.matchers.datetime.HasWeekday(day)[source]¶
Match if date has matching day of the week.
- Parameters:
day (
int|Matcher[int]) – Day of week, with 0 being Monday, 1 being Tuesday, and so on.
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
The “brunns.matchers.dbapi” module¶
- class brunns.matchers.dbapi.SelectReturnsRowsMatching(select, row_matcher)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
Connection) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
The “brunns.matchers.html” module¶
- class brunns.matchers.html.HtmlWithTag(tag_matcher, name=None, id_=None)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- class brunns.matchers.html.TagWith(name=<IsAnything(ANYTHING)>, string=<IsAnything(ANYTHING)>, clazz=<IsAnything(ANYTHING)>, attributes=<IsAnything(ANYTHING)>)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- class brunns.matchers.html.HtmlHasTable(table_matcher, id_=<IsAnything(ANYTHING)>)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- class brunns.matchers.html.TableHasRow(row_matcher=<IsAnything(ANYTHING)>, cells_matcher=<IsAnything(ANYTHING)>, index_matcher=<IsAnything(ANYTHING)>, *, header_row=False)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
Tag) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- brunns.matchers.html.has_title(title)[source]¶
Matches HTML containing a <title> tag with the specified text content.
Requires brunns-matchers to have been installed with the
htmlextra.
- brunns.matchers.html.has_named_tag(name, matcher)[source]¶
Matches HTML containing a tag with a specific name that satisfies a matcher.
Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
name – The HTML tag name to find (e.g., ‘div’, ‘span’).
matcher – A matcher to apply to the found tag(s).
- Return type:
- brunns.matchers.html.has_id_tag(id_, matcher)[source]¶
Matches HTML containing a tag with a specific ‘id’ attribute that satisfies a matcher.
Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
id – The HTML id attribute to find.
matcher – A matcher to apply to the found tag(s).
- Return type:
- brunns.matchers.html.tag_has_string(matcher)[source]¶
Matches a BeautifulSoup Tag if its text content matches the given criteria.
Requires brunns-matchers to have been installed with the
htmlextra.
- brunns.matchers.html.has_class(clazz)[source]¶
Matches a BeautifulSoup Tag if it possesses the specified CSS class.
Requires brunns-matchers to have been installed with the
htmlextra.
- brunns.matchers.html.has_table(matcher, id_=<IsAnything(ANYTHING)>)[source]¶
Matches HTML containing a <table> element satisfying the given table matcher.
Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
matcher – A matcher to apply to the table Tag.
id – Optional matcher or string for the table’s ‘id’ attribute.
- Return type:
- brunns.matchers.html.has_row(row_matches=<IsAnything(ANYTHING)>, cells_match=<IsAnything(ANYTHING)>, index_matches=<IsAnything(ANYTHING)>, *, header_row=False)[source]¶
Matches a table Tag if it contains a row satisfying the specified criteria.
Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
row_matches – Matcher for the <tr> Tag itself.
cells_match – Matcher for the sequence of cells (<td>) within the row.
index_matches – Matcher for the row’s index within the table.
header_row – If True, looks for <th> cells instead of <td>.
- Return type:
- brunns.matchers.html.has_header_row(cells_matcher=<IsAnything(ANYTHING)>, row_matcher=<IsAnything(ANYTHING)>)[source]¶
Matches a table Tag if it contains a header row satisfying the specified criteria.
This is a convenience wrapper around
has_rowwithheader_row=True.Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
cells_matcher – Matcher for the sequence of header cells (<th>) within the row.
row_matcher – Matcher for the <tr> Tag itself.
- Return type:
- brunns.matchers.html.has_id(id_)[source]¶
Matches a BeautifulSoup Tag if it has the specified element ID.
Requires brunns-matchers to have been installed with the
htmlextra.- Parameters:
id – The string ID or a matcher for the ID.
- Return type:
- brunns.matchers.html.has_attributes(matcher)[source]¶
Matches a BeautifulSoup Tag if its attributes dictionary matches the provided matcher.
Requires brunns-matchers to have been installed with the
htmlextra.
- brunns.matchers.html.has_link(id_=<IsAnything(ANYTHING)>, clazz=<IsAnything(ANYTHING)>, href=<IsAnything(ANYTHING)>)[source]¶
Matches HTML containing an anchor (<a>) tag with specific attributes.
Requires brunns-matchers to have been installed with the
htmlextra.
The “brunns.matchers.matcher” module¶
- class brunns.matchers.matcher.MismatchesWith(value_not_to_match, expected_message)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
Matcher[Any]) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- brunns.matchers.matcher.mismatches_with(value_not_to_match, expected_message)[source]¶
Matches if the matcher under test fails to match the value, and provides the expected mismatch message.
This is useful for testing custom matchers to ensure they reject invalid values and provide helpful diagnostics.
- Parameters:
- Return type:
- brunns.matchers.matcher.mismatches(value_not_to_match)[source]¶
Matches if the matcher under test fails to match the value, regardless of the message.
- Parameters:
value_not_to_match (
Any) – The value that the matcher under test should reject.- Return type:
- class brunns.matchers.matcher.MatchesWith(value_to_match, expected_message)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
Matcher[Any]) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- brunns.matchers.matcher.matches_with(value_to_match, expected_message)[source]¶
Matches if the matcher under test successfully matches the value, and provides the expected match description.
- Parameters:
- Return type:
The “brunns.matchers.meta” module¶
- class brunns.matchers.meta.BaseAutoMatcher[source]¶
Dynamically create matchers for classes. Use like so:
from dataclasses import dataclass from typing import Optional from hamcrest import assert_that, starts_with from hamcrest.core.matcher import Matcher from pydantic import BaseModel from brunns.matchers.meta import BaseAutoMatcher @dataclass class Status: id: int code: str reason: Optional[str] = None class StatusMatcher(BaseAutoMatcher[Status]): ... def is_status() -> Matcher[Status]: return StatusMatcher() actual = Status(code="ACTIVE", id=99) assert_that(actual, is_status().with_code(starts_with("ACT")).and_reason(None)) assert_that(actual, is_status().with_id(42)) # Will fail
Works only for classes with
__annotations__; typically manually annotated classes,dataclasses.dataclassandpydantic.BaseModelinstances.- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
match_description (
Description) – The description to be built or appended to.
- Return type:
The “brunns.matchers.mock” module¶
- class brunns.matchers.mock.CallHasPositionalArg(index, expected)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
_Call) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- class brunns.matchers.mock.CallHasKeywordArg(key, expected)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
_Call) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- class brunns.matchers.mock.HasCall(call_matcher)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- class brunns.matchers.mock.CallHasArgs(*args, **kwargs)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
_Call) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- brunns.matchers.mock.call_has_arg(arg, expected)[source]¶
Matches a
mock.callif a specific positional or keyword argument satisfies the matcher.- Parameters:
- Return type:
BaseMatcher[_Call]
- brunns.matchers.mock.has_call(call_matcher)[source]¶
Matches a
unittest.mock.Mockobject if any of its calls satisfy the given matcher.
- brunns.matchers.mock.call_has_args(*args, **kwargs)[source]¶
Matches a
mock.callif it matches all provided positional and keyword arguments.The match is loose for keyword arguments (only specified keys are checked), but positional arguments are checked in order.
- Parameters:
args – Expected values or matchers for positional arguments.
kwargs – Expected values or matchers for keyword arguments.
- Return type:
The “brunns.matchers.object” module¶
- brunns.matchers.object.has_repr(expected)[source]¶
Matches if the object’s
repr()matches the expected string or matcher.
- class brunns.matchers.object.HasRepr(expected)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- brunns.matchers.object.has_identical_properties_to(expected, ignoring=None)[source]¶
Matches an object if its public properties and attributes are identical to the expected object’s.
This matcher performs a deep recursive comparison of all public attributes (those not starting with
_) and properties. It gracefully handles nested dictionaries and sequences.
- class brunns.matchers.object.HasIdenticalPropertiesTo(expected, ignoring=None)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- brunns.matchers.object.equal_vars(left, right, ignoring=None)[source]¶
Test if two objects are equal using public vars() and properties if available, with == otherwise.
- class brunns.matchers.object.Truthy[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- brunns.matchers.object.true()[source]¶
Matches any value that evaluates to True in a boolean context (truthy).
- brunns.matchers.object.false()[source]¶
Matches any value that evaluates to False in a boolean context (falsy).
- brunns.matchers.object.between(lower, upper, *, lower_inclusive=True, upper_inclusive=True)[source]¶
Matches if a value is within a specific range.
- Parameters:
lower (
Any) – The lower bound of the range.upper (
Any) – The upper bound of the range.lower_inclusive – If True, the range includes the lower bound (>=). If False, it is exclusive (>). Defaults to True.
upper_inclusive – If True, the range includes the upper bound (<=). If False, it is exclusive (<). Defaults to True.
- Return type:
- Returns:
A matcher for the specified range.
The “brunns.matchers.path” module¶
- class brunns.matchers.path.PathMatcher[source]¶
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
match_description (
Description) – The description to be built or appended to.
- Return type:
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- and_anchor(item)¶
Matches the path’s anchor (drive and root combined).
- and_name(item)¶
Matches the path’s name (final component).
- and_parent(item)¶
Matches the path’s parent directory.
- and_parents(item)¶
Matches the path’s sequence of parent directories.
- and_parts(item)¶
Matches the path’s component sequence.
- and_root(item)¶
Matches the path’s root string.
- and_stem(item)¶
Matches the path’s stem (final component without its extension).
- and_suffix(item)¶
Matches the path’s file suffix (extension).
- and_suffixes(item)¶
Matches the path’s list of file suffixes (extensions).
- which_exists()[source]¶
Matches that the path exists on the filesystem.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_which_exists()¶
Matches that the path exists on the filesystem.
- Return type:
Self- Returns:
This matcher instance for chaining.
- which_does_not_exist()[source]¶
Matches that the path does not exist on the filesystem.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_which_does_not_exist()¶
Matches that the path does not exist on the filesystem.
- Return type:
Self- Returns:
This matcher instance for chaining.
- which_is_a_file()[source]¶
Matches that the path is a regular file.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_is_a_file()¶
Matches that the path is a regular file.
- Return type:
Self- Returns:
This matcher instance for chaining.
- which_is_a_directory()[source]¶
Matches that the path is a directory.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_is_a_directory()¶
Matches that the path is a directory.
- Return type:
Self- Returns:
This matcher instance for chaining.
- which_is_absolute()[source]¶
Matches that the path is absolute.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_is_absolute()¶
Matches that the path is absolute.
- Return type:
Self- Returns:
This matcher instance for chaining.
- which_is_relative()[source]¶
Matches that the path is not absolute.
- Return type:
Self- Returns:
This matcher instance for chaining.
- and_is_relative()¶
Matches that the path is not absolute.
- Return type:
Self- Returns:
This matcher instance for chaining.
- brunns.matchers.path.is_path()[source]¶
Matches a
pathlib.Pathor string filepath.This function returns a
PathMatcherwhich can be refined using builder methods to match specific parts of thepathlib.Path(e.g..with_name(...),.with_suffix(...)).- Return type:
- Returns:
A matcher for
pathlib.Pathobjects or string filepaths.
The “brunns.matchers.response” module¶
- class brunns.matchers.response.ResponseProtocol(*args, **kwargs)[source]¶
Structural typing for HTTP Response objects.
- brunns.matchers.response.is_response()[source]¶
Matches an HTTP response object (requests, httpx, etc.).
This function returns a
ResponseMatcherwhich can be refined using builder methods (e.g..with_status_code(200)).- Return type:
- Returns:
A matcher for HTTP responses.
- class brunns.matchers.response.ResponseMatcher(*, status_code=<IsAnything(ANYTHING)>, body=<IsAnything(ANYTHING)>, content=<IsAnything(ANYTHING)>, json=<IsAnything(ANYTHING)>, headers=<IsAnything(ANYTHING)>, cookies=<IsAnything(ANYTHING)>, elapsed=<IsAnything(ANYTHING)>, history=<IsAnything(ANYTHING)>, url=<IsAnything(ANYTHING)>, encoding=<IsAnything(ANYTHING)>)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
TypeVar(R, bound=ResponseProtocol)) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
TypeVar(R, bound=ResponseProtocol)) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- with_status_code(status_code)[source]¶
Matches if the response status code matches the given value or matcher.
- and_status_code(status_code)¶
Matches if the response status code matches the given value or matcher.
- and_body(body)¶
Matches if the response body text matches the given value or matcher.
- with_content(content)[source]¶
Matches if the response binary content matches the given value or matcher.
- and_content(content)¶
Matches if the response binary content matches the given value or matcher.
- with_json(json)[source]¶
Matches if the response JSON body matches the given value or matcher.
The response body is parsed as JSON before matching.
- Parameters:
json (
str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None|Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None]) – The expected JSON structure (dict, list, etc.) or matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- and_json(json)¶
Matches if the response JSON body matches the given value or matcher.
The response body is parsed as JSON before matching.
- Parameters:
json (
str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None|Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None]) – The expected JSON structure (dict, list, etc.) or matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- and_headers(headers)¶
Matches if the response headers match the given value or matcher.
- and_cookies(cookies)¶
Matches if the response cookies match the given value or matcher.
- with_elapsed(elapsed)[source]¶
Matches if the response elapsed time matches the given value or matcher.
- and_elapsed(elapsed)¶
Matches if the response elapsed time matches the given value or matcher.
- with_history(history)[source]¶
Matches if the response history (redirects) matches the given sequence or matcher.
- Parameters:
history (
Sequence[ResponseProtocol|Matcher[ResponseProtocol]] |Matcher[Sequence[ResponseProtocol|Matcher[ResponseProtocol]]]) – The expected sequence of responses/matchers or a sequence matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- and_history(history)¶
Matches if the response history (redirects) matches the given sequence or matcher.
- Parameters:
history (
Sequence[ResponseProtocol|Matcher[ResponseProtocol]] |Matcher[Sequence[ResponseProtocol|Matcher[ResponseProtocol]]]) – The expected sequence of responses/matchers or a sequence matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- with_url(url)[source]¶
Matches if the response URL matches the given value or matcher.
- Parameters:
url (
UrlProtocol|Matcher[UrlProtocol]) – The expected URL string, object, or matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- and_url(url)¶
Matches if the response URL matches the given value or matcher.
- Parameters:
url (
UrlProtocol|Matcher[UrlProtocol]) – The expected URL string, object, or matcher.- Return type:
Self- Returns:
ResponseMatcher, for chaining.
- brunns.matchers.response.redirects_to(url_matcher)[source]¶
Is a response a redirect to a URL matching the supplied matcher?
Matches if the status code is between 300 and 399 and the
Locationheader matches the provided URL matcher.- Parameters:
url_matcher (
UrlProtocol|Matcher[UrlProtocol]) – The expected URL (string or matcher) found in the Location header.- Return type:
- Returns:
A matcher for redirect responses.
- brunns.matchers.response.response_with(status_code=<IsAnything(ANYTHING)>, body=<IsAnything(ANYTHING)>, content=<IsAnything(ANYTHING)>, json=<IsAnything(ANYTHING)>, headers=<IsAnything(ANYTHING)>)[source]¶
Matches a response with specific attributes.
Deprecated since version 2.3.0: Use
is_response()and its builder methods instead.- Return type:
The “brunns.matchers.rss” module¶
- class brunns.matchers.rss.RssFeedMatcher[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
UrlProtocol) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
UrlProtocol) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_title(title)¶
Matches the title of the RSS feed.
- with_link(link)[source]¶
Matches the link URL of the RSS feed.
- Parameters:
link (
UrlProtocol|Matcher[UrlProtocol]) – Expected link URL or a matcher for the link.- Return type:
Self- Returns:
This matcher instance for chaining.
- and_link(link)¶
Matches the link URL of the RSS feed.
- Parameters:
link (
UrlProtocol|Matcher[UrlProtocol]) – Expected link URL or a matcher for the link.- Return type:
Self- Returns:
This matcher instance for chaining.
- and_description(description)¶
Matches the description of the RSS feed.
- and_published(published)¶
Matches the publication datetime of the RSS feed.
- class brunns.matchers.rss.RssFeedEntryMatcher[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
FeedParserDict|str) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
FeedParserDict|str) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- and_title(title)¶
Matches the title of the RSS feed entry.
- with_link(link)[source]¶
Matches the link URL of the RSS feed entry.
- Parameters:
link (
URL|Matcher[URL]) – Expected link URL or a matcher for the link.- Return type:
Self- Returns:
This matcher instance for chaining.
- and_link(link)¶
Matches the link URL of the RSS feed entry.
- Parameters:
link (
URL|Matcher[URL]) – Expected link URL or a matcher for the link.- Return type:
Self- Returns:
This matcher instance for chaining.
- and_description(description)¶
Matches the description of the RSS feed entry.
- and_published(published)¶
Matches the publication datetime of the RSS feed entry.
- and_authors(authors)¶
Matches the list of author names for the RSS feed entry.
- class brunns.matchers.rss.RssCategoryMatcher[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
FeedParserDict) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
FeedParserDict) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_text(text)¶
Matches the category text (term) of the RSS category.
- brunns.matchers.rss.is_rss_feed()[source]¶
Matches a string (or URL-like object) as an RSS feed using
feedparser.The string is parsed as an RSS feed, and the resulting structure is checked. This matcher uses a builder pattern (e.g.,
.with_title(...)) to refine the match.Requires brunns-matchers to have been installed with the rss extra.
- Return type:
- Returns:
A matcher for RSS feed content.
- brunns.matchers.rss.is_rss_entry()[source]¶
Matches a single RSS feed entry (item) within an RSS feed.
This matcher operates on
feedparser.FeedParserDictobjects, typically found in theentrieslist of a parsed feed.Requires brunns-matchers to have been installed with the rss extra.
- Return type:
- Returns:
A matcher for an RSS feed entry.
- brunns.matchers.rss.is_rss_category()[source]¶
Matches a single RSS category.
This matcher operates on
feedparser.FeedParserDictobjects, typically found in thecategorieslist of a parsed feed item.Requires brunns-matchers to have been installed with the rss extra.
- Return type:
- Returns:
A matcher for an RSS category.
The “brunns.matchers.scripttest” module¶
PyHamcrest matchers for scripttest ProcResult objects.
- class brunns.matchers.scripttest.ProcResultProtocol(*args, **kwargs)[source]¶
Structural typing for scripttest.ProcResult objects.
- brunns.matchers.scripttest.is_proc_result()[source]¶
Matches a
scripttest.ProcResultobject.This function returns a
ProcResultMatcherwhich can be refined using builder methods (e.g..with_returncode(0)).- Return type:
- Returns:
A matcher for scripttest ProcResult objects.
- class brunns.matchers.scripttest.ProcResultMatcher(*, returncode=<IsAnything(ANYTHING)>, stdout=<IsAnything(ANYTHING)>, stderr=<IsAnything(ANYTHING)>, args=<IsAnything(ANYTHING)>, stdin=<IsAnything(ANYTHING)>, files_created=<IsAnything(ANYTHING)>, files_deleted=<IsAnything(ANYTHING)>, files_updated=<IsAnything(ANYTHING)>)[source]¶
Matches
scripttest.ProcResult.- Parameters:
returncode (
int|Matcher[int]) – Expected return code (exit code).stdout (
str|Matcher[str]) – Expected standard output text.args (
Sequence[str] |Matcher[Sequence[str]]) – Expected command arguments.stdin (
bytes|Matcher[bytes]) – Expected standard input bytes.files_created (
Mapping[str,Any] |Matcher[Mapping[str,Any]]) – Expected files created dictionary.files_deleted (
Mapping[str,Any] |Matcher[Mapping[str,Any]]) – Expected files deleted dictionary.files_updated (
Mapping[str,Any] |Matcher[Mapping[str,Any]]) – Expected files updated dictionary.
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
TypeVar(P, bound=ProcResultProtocol)) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
TypeVar(P, bound=ProcResultProtocol)) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_returncode(returncode)¶
Matches if the return code matches the given value or matcher.
- and_stdout(stdout)¶
Matches if the stdout text matches the given value or matcher.
- and_stderr(stderr)¶
Matches if the stderr text matches the given value or matcher.
- and_args(args)¶
Matches if the command arguments match the given value or matcher.
- and_stdin(stdin)¶
Matches if the stdin bytes match the given value or matcher.
- with_files_created(files_created)[source]¶
Matches if the files created dictionary matches the given value or matcher.
- and_files_created(files_created)¶
Matches if the files created dictionary matches the given value or matcher.
- with_files_deleted(files_deleted)[source]¶
Matches if the files deleted dictionary matches the given value or matcher.
- and_files_deleted(files_deleted)¶
Matches if the files deleted dictionary matches the given value or matcher.
The “brunns.matchers.smtp” module¶
- class brunns.matchers.smtp.Email(to_name, to_address, from_name, from_address, subject, body_text)[source]¶
- brunns.matchers.smtp.is_email()[source]¶
Matches a string as an RFC 822 / MIME email message.
This function returns an
EmailWithmatcher which can be refined using builder methods (e.g.,.with_subject(...)). It parses the string using Python’semailmodule.- Return type:
- Returns:
A matcher for email strings.
- class brunns.matchers.smtp.EmailWith(*, to_name=<IsAnything(ANYTHING)>, to_address=<IsAnything(ANYTHING)>, from_name=<IsAnything(ANYTHING)>, from_address=<IsAnything(ANYTHING)>, subject=<IsAnything(ANYTHING)>, body_text=<IsAnything(ANYTHING)>)[source]¶
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
match_description (
Description) – The description to be built or appended to.
- Return type:
- and_to_name(to_name)¶
Matches if the email ‘To’ name matches the given value or matcher.
- with_to_address(to_address)[source]¶
Matches if the email ‘To’ address matches the given value or matcher.
- and_to_address(to_address)¶
Matches if the email ‘To’ address matches the given value or matcher.
- with_from_name(from_name)[source]¶
Matches if the email ‘From’ name matches the given value or matcher.
- and_from_name(from_name)¶
Matches if the email ‘From’ name matches the given value or matcher.
- with_from_address(from_address)[source]¶
Matches if the email ‘From’ address matches the given value or matcher.
- and_from_address(from_address)¶
Matches if the email ‘From’ address matches the given value or matcher.
- and_subject(subject)¶
Matches if the email subject matches the given value or matcher.
- brunns.matchers.smtp.email_with(*, to_name=<IsAnything(ANYTHING)>, to_address=<IsAnything(ANYTHING)>, from_name=<IsAnything(ANYTHING)>, from_address=<IsAnything(ANYTHING)>, subject=<IsAnything(ANYTHING)>, body_text=<IsAnything(ANYTHING)>)[source]¶
Matches an email string with specific attributes.
Deprecated since version 2.3.0: Use
is_email()and its builder methods instead.
The “brunns.matchers.url” module¶
- brunns.matchers.url.is_url()[source]¶
Matches a string (or
furl/yarl.URLobject) as a URL.This function returns a
UrlWithmatcher which can be refined using builder methods to match specific parts of the URL (e.g..with_host(...),.with_query(...)).Requires brunns-matchers to have been installed with the url extra.
- Return type:
- Returns:
A matcher for URL components.
- class brunns.matchers.url.UrlWith(host=<IsAnything(ANYTHING)>, path=<IsAnything(ANYTHING)>, query=<IsAnything(ANYTHING)>, fragment=<IsAnything(ANYTHING)>)[source]¶
Matches specific components of a URL.
The matcher parses the actual value using the
furllibrary.- Parameters:
host (
str|Matcher[str|None] |None) – Expected hostname (e.g., “google.com”).path (
str|Matcher[str]) – Expected path string (e.g., “/search”).query (
Mapping[str,str|Matcher[str]] |Matcher[Mapping[str,str|Matcher[str]]]) – Expected query parameters dictionary.fragment (
str|Matcher[str]) – Expected URL fragment (hash).
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
TypeVar(U, bound=UrlProtocol)) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
TypeVar(U, bound=UrlProtocol)) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_scheme(scheme)¶
Matches if the URL scheme matches the given value or matcher.
- and_username(username)¶
Matches if the URL username matches the given value or matcher.
- with_user(username)¶
Matches if the URL username matches the given value or matcher.
- and_user(username)¶
Matches if the URL username matches the given value or matcher.
- and_password(password)¶
Matches if the URL password matches the given value or matcher.
- and_host(host)¶
Matches if the URL host matches the given value or matcher.
- and_port(port)¶
Matches if the URL port matches the given value or matcher.
- and_path(path)¶
Matches if the URL path matches the given value or matcher.
- with_path_segments(path_segments)[source]¶
Matches if the URL path segments match the given sequence or matcher.
- and_path_segments(path_segments)¶
Matches if the URL path segments match the given sequence or matcher.
- with_query(query)[source]¶
Matches if the URL query parameters match the given dictionary or matcher.
- and_query(query)¶
Matches if the URL query parameters match the given dictionary or matcher.
- brunns.matchers.url.url_with_host(matcher)[source]¶
Matches URL with specific host.
Deprecated since version 2.3.0: Use
is_url().with_host(...)instead.
- brunns.matchers.url.url_with_path(matcher)[source]¶
Matches URL with specific path.
Deprecated since version 2.3.0: Use
is_url().with_path(...)instead.
- brunns.matchers.url.url_with_query(matcher)[source]¶
Matches URL with specific query parameters.
Deprecated since version 2.3.0: Use
is_url().with_query(...)instead.
- brunns.matchers.url.url_with_fragment(matcher)[source]¶
Matches URL with specific fragment.
Deprecated since version 2.3.0: Use
is_url().with_fragment(...)instead.
- brunns.matchers.url.to_host(matcher)[source]¶
Matches URL with specific host.
Deprecated since version 2.2.0: Use
is_url().with_host(...)instead.
- brunns.matchers.url.with_path(matcher)[source]¶
Matches URL with specific path.
Deprecated since version 2.2.0: Use
is_url().with_path(...)instead.
The “brunns.matchers.werkzeug” module¶
- class brunns.matchers.werkzeug.ResponseProtocol(*args, **kwargs)[source]¶
Structural typing for Werkzeug Response objects.
- brunns.matchers.werkzeug.is_werkzeug_response()[source]¶
Matches a
werkzeug.test.TestResponseobject (e.g. from Flask test client).This function returns a
WerkzeugResponseMatcherwhich can be refined using builder methods (e.g.,.with_status_code(200)).- Return type:
- Returns:
A matcher for Werkzeug/Flask test responses.
- class brunns.matchers.werkzeug.WerkzeugResponseMatcher[source]¶
Matches a
werkzeug.test.TestResponseobject.This matcher is useful for testing Flask applications using the built-in test client.
- describe_to(description)[source]¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (
Description) – The description to be built or appended to.- Return type:
- describe_mismatch(item, mismatch_description)[source]¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isFalse, but will not check this.- Parameters:
item (
TypeVar(R, bound=ResponseProtocol)) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(item, match_description)[source]¶
Generates a description of why the matcher has accepted the item.
The description may be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)isTrue, but will not check this.- Parameters:
item (
TypeVar(R, bound=ResponseProtocol)) – The item that theMatcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- with_status_code(status_code)[source]¶
Matches if the response status code matches the given value or matcher.
- and_status_code(status_code)¶
Matches if the response status code matches the given value or matcher.
- and_text(text)¶
Matches if the response body text matches the given value or matcher.
- with_mimetype(mimetype)[source]¶
Matches if the response mimetype matches the given value or matcher.
- and_mimetype(mimetype)¶
Matches if the response mimetype matches the given value or matcher.
- with_json(json)[source]¶
Matches if the response JSON body matches the given value or matcher.
The response body is parsed as JSON before matching.
- Parameters:
json (
str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None|Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None]) – The expected JSON structure or matcher.- Return type:
Self- Returns:
Self, for chaining.
- and_json(json)¶
Matches if the response JSON body matches the given value or matcher.
The response body is parsed as JSON before matching.
- Parameters:
json (
str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None|Matcher[str|int|float|bool|Sequence[str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |Mapping[str,str|int|float|bool|Sequence[JsonValue] |Mapping[str, JsonValue] |None] |None]) – The expected JSON structure or matcher.- Return type:
Self- Returns:
Self, for chaining.
- brunns.matchers.werkzeug.redirects_to(url_matcher)[source]¶
Matches if the Werkzeug response is a redirect to the specified URL.
Checks if the status code is between 300 and 399 and the
Locationheader matches.