joythief.strings module

Matchers for the text sequence type (str).

class joythief.strings.JsonString(expected=<object object>)[source]

Bases: Matcher[str]

Matches any str instance representing JSON.

Parameters:

expected (Any) – What the result of parsing the JSON should be. If omitted, any valid JSON string is matched.

class joythief.strings.StringContaining(substring)[source]

Bases: Matcher[str]

Matches any str instance containing a substring.

Added in version 0.9.0.

Parameters:

substring (str) – the substring to search for

class joythief.strings.StringMatching(pattern: Pattern[str])[source]
class joythief.strings.StringMatching(pattern: str, *, flags: int = 0)

Bases: Matcher[str]

Matches any str instance matching a regular expression.

Parameters:
  • pattern (str | Pattern[str]) – Regex pattern to match, as a string or compiled pattern.

  • flags (int) – Any flags to compile a str pattern with

Raises:

ValueError – if flags are provided with a pre-compiled pattern.

classmethod iso8601()[source]

Create a matcher for strings representing ISO 8601 timestamps.

Added in version 0.4.0.

Matches the %Y-%m-%dT%H:%M:%S.%f format as created by e.g. datetime.datetime.isoformat():

'2025-07-22T14:16:48.708298'

Note the match is only on structure, it does not attempt to validate the actual datetime represented by the string.

Return type:

Matcher[str]

classmethod uuid()[source]

Create a matcher for strings representing UUIDs.

Added in version 0.4.0.

Matches the 8-4-4-4-12 hexadecimal format as created by e.g. stringifying UUID:

'36962eb6-d198-4661-9d97-437796e5146b'
Return type:

Matcher[str]

class joythief.strings.UrlString(*, scheme=None, hostname=None, path=None, query=None)[source]

Bases: Matcher[str]

Matches any str instance representing a URL.

The string is parsed with urlparse() and compared attribute-by-attribute. Any attributes not provided are ignored.

Parameters:
Raises:

TypeError – if no arguments are provided.