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.
- 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(json_string, 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.
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:
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(conn, 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 – The item that the
Matcherhas 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(actual, 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 – The item that the
Matcherhas rejected.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(table, 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 – The item that the
Matcherhas 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.
- brunns.matchers.html.has_named_tag(name, matcher)[source]¶
Matches HTML containing a tag with a specific name that satisfies a matcher.
- 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.
- 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.
- brunns.matchers.html.has_class(clazz)[source]¶
Matches a BeautifulSoup Tag if it possesses the specified CSS class.
- brunns.matchers.html.has_table(matcher, id_=<IsAnything(ANYTHING)>)[source]¶
Matches HTML containing a <table> element satisfying the given table matcher.
- 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.
- 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.- 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.
- 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.
- 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.
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(matcher_under_test, 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.
- 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(matcher_under_test, 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.
- 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(status_code="ACTIVE", count=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(actual_call, 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 – The item that the
Matcherhas 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(actual_call, 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 – The item that the
Matcherhas 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(mock, 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 – The item that the
Matcherhas rejected.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(call, 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 – The item that the
Matcherhas 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.response” module¶
- brunns.matchers.response.is_response()[source]¶
Matches a
requests.Responseorhttpx.Responseobject.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]¶
Matches
requests.Responseorhttpx.Response.- Parameters:
content (
bytes|Matcher[bytes]) – Expected raw binary content.headers (
Mapping[str,str|Matcher[str]] |Matcher[Mapping[str,str|Matcher[str]]]) – Expected headers dictionary.cookies (
Mapping[str,str|Matcher[str]] |Matcher[Mapping[str,str|Matcher[str]]]) – Expected cookies dictionary.elapsed (
timedelta|Matcher[timedelta]) – Expected elapsed time (timedelta).history (
Sequence[Response|Response|Matcher[Response|Response]] |Matcher[Sequence[Response|Response|Matcher[Response|Response]]]) – Expected history sequence.encoding (
str|None|Matcher[str|None]) – Expected encoding string.
- 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(response, 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 – The item that the
Matcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(response, 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 – The item that the
Matcherhas 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)[source]¶
Matches if the response status code matches the given value or matcher.
A synonym for
with_status_code().
- and_body(body)[source]¶
Matches if the response body text matches the given value or matcher.
A synonym for
with_body().
- with_content(content)[source]¶
Matches if the response binary content matches the given value or matcher.
- and_content(content)[source]¶
Matches if the response binary content matches the given value or matcher.
A synonym for
with_content().
- 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.
- and_json(json)[source]¶
Matches if the response JSON body matches the given value or matcher.
A synonym for
with_json().
- and_headers(headers)[source]¶
Matches if the response headers match the given value or matcher.
A synonym for
with_headers().
- and_cookies(cookies)[source]¶
Matches if the response cookies match the given value or matcher.
A synonym for
with_cookies().
- with_elapsed(elapsed)[source]¶
Matches if the response elapsed time matches the given value or matcher.
- and_elapsed(elapsed)[source]¶
Matches if the response elapsed time matches the given value or matcher.
A synonym for
with_elapsed().
- with_history(history)[source]¶
Matches if the response history (redirects) matches the given sequence or matcher.
- and_history(history)[source]¶
Matches if the response history (redirects) matches the given sequence or matcher.
A synonym for
with_history().
- and_url(url)[source]¶
Matches if the response URL matches the given value or matcher.
A synonym for
with_url().
- 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.
- 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:
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:
- 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) – 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) – The item that theMatcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- 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.- Return type:
- Returns:
A matcher for RSS feed content.
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(actual_email, 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 – The item that the
Matcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(actual_email, 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 – The item that the
Matcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_to_name(to_name)[source]¶
Matches if the email ‘To’ name matches the given value or matcher.
A synonym for
with_to_name().
- with_to_address(to_address)[source]¶
Matches if the email ‘To’ address matches the given value or matcher.
- and_to_address(to_address)[source]¶
Matches if the email ‘To’ address matches the given value or matcher.
A synonym for
with_to_address().
- with_from_name(from_name)[source]¶
Matches if the email ‘From’ name matches the given value or matcher.
- and_from_name(from_name)[source]¶
Matches if the email ‘From’ name matches the given value or matcher.
A synonym for
with_from_name().
- with_from_address(from_address)[source]¶
Matches if the email ‘From’ address matches the given value or matcher.
- and_from_address(from_address)[source]¶
Matches if the email ‘From’ address matches the given value or matcher.
A synonym for
with_from_address().
- and_subject(subject)[source]¶
Matches if the email subject matches the given value or matcher.
A synonym for
with_subject().
- 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(...)).- 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]) – 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(url, 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 – The item that the
Matcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(url, 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 – The item that the
Matcherhas accepted.match_description (
Description) – The description to be built or appended to.
- Return type:
- and_scheme(scheme)[source]¶
Matches if the URL scheme matches the given value or matcher.
A synonym for
with_scheme().
- and_username(username)[source]¶
Matches if the URL username matches the given value or matcher.
A synonym for
with_username().
- and_password(password)[source]¶
Matches if the URL password matches the given value or matcher.
A synonym for
with_password().
- and_host(host)[source]¶
Matches if the URL host matches the given value or matcher.
A synonym for
with_host().
- and_port(port)[source]¶
Matches if the URL port matches the given value or matcher.
A synonym for
with_port().
- and_path(path)[source]¶
Matches if the URL path matches the given value or matcher.
A synonym for
with_path().
- with_path_segments(path_segments)[source]¶
Matches if the URL path segments match the given sequence or matcher.
- and_path_segments(path_segments)[source]¶
Matches if the URL path segments match the given sequence or matcher.
A synonym for
with_path_segments().
- with_query(query)[source]¶
Matches if the URL query parameters match the given dictionary or matcher.
- and_query(query)[source]¶
Matches if the URL query parameters match the given dictionary or matcher.
A synonym for
with_query().
- 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¶
- 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(response, 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 – The item that the
Matcherhas rejected.mismatch_description (
Description) – The description to be built or appended to.
- Return type:
- describe_match(response, 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 – The item that the
Matcherhas 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)[source]¶
Matches if the response status code matches the given value or matcher.
A synonym for
with_status_code().
- with_text(text)[source]¶
Matches if the response body text matches the given value or matcher.
- and_text(text)[source]¶
Matches if the response body text matches the given value or matcher.
A synonym for
with_text().
- with_mimetype(mimetype)[source]¶
Matches if the response mimetype matches the given value or matcher.
- and_mimetype(mimetype)[source]¶
Matches if the response mimetype matches the given value or matcher.
A synonym for
with_mimetype().
- 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.
- and_json(json)[source]¶
Matches if the response JSON body matches the given value or matcher.
A synonym for
with_json().
- and_headers(headers)[source]¶
Matches if the response headers match the given value or matcher.
A synonym for
with_headers().