Resolutions API

These are the Resolutions included in ScreenPy.

ContainsItemMatching

Aliases: ContainItemMatching

class ContainsItemMatching(pattern: str)

Match a sequence containing an item matching a regular expression.

Examples:

the_actor.should(
    # matches "Spam...", "Spam spam...", "Spam spam spam..."
    See.the(Text.of_all(MENU_ITEMS), ContainsItemMatching(r"^([Ss]pam ?)+"))
)

ContainsTheEntry

Aliases: ContainsTheEntries, ContainTheEntries, ContainTheEntry,

class ContainsTheEntry(**kv_args: V)
class ContainsTheEntry(kv_args: Mapping[K, V] | list[tuple[K, V]])
class ContainsTheEntry(*kv_args: V)

Match a dictionary containing the specified key/value pair(s).

Examples:

the_actor.should(
    See.the(
        HeadersOfTheLastResponse(), ContainTheEntry(Authorization="Bearer 1")
    )
)

the_actor.should(
    See.the(
        EnglishDictionary(), ContainsTheEntry({"Python": "a large snake."})
    )
)

the_actor.should(See.the(MathTestAnswers(), ContainsTheEntry("Problem3", 45)))

ContainsTheItem

Aliases: ContainTheItem

class ContainsTheItem(item: T)

Match an iterable containing a specific item.

Examples:

the_actor.should(
    See.the(Text.of_all(SEARCH_RESULTS), ContainsTheItem("The Droids"))
)

ContainsTheKey

Aliases: ContainTheKey

class ContainsTheKey(key: K)

Match a dictionary containing a specific key.

Examples:

the_actor.should(See.the(LastResponseBody(), ContainsTheKey("skeleton")))

ContainsTheText

Aliases: ContainTheText

class ContainsTheText(text: str)

Match a specific substring of a string.

Examples:

the_actor.should(
    See.the(Text.of_the(WELCOME_MESSAGE), ContainsTheText("Hello,"))
)

ContainsTheValue

Aliases: ContainTheValue

class ContainsTheValue(value: V)

Match a dictionary containing a specific value.

Examples:

the_actor.should(
    See.the(Cookies(), ContainTheValue("pumpernickle"))
)

EndsWith

Aliases: EndWith

class EndsWith(postfix: str)

Match a string which ends with the given substring.

Examples:

the_actor.should(
    See.the(Text.of_the(LOGIN_ERROR), EndsWith("username or password."))
)

HasLength

Aliases: HaveLength

class HasLength(length: int)

Match against a collection with a specific length.

Examples:

the_actor.should(
    See.the(Selected.options_from(INDUSTRIES), HasLength(5))
)

IsCloseTo

Aliases: CloseTo

class IsCloseTo(num: int, delta: int = 1)

Matches a value that falls within the range specified by the given delta.

Examples:

the_actor.should(
    See.the(Number.of(BALLOONS), IsCloseTo(FILLED_BALLOONS_COUNT, delta=25))
)

IsEmpty

Aliases: Empty

class IsEmpty

Match on an empty collection.

Examples:

the_actor.should(See.the(List.of_all(VIDEO_FRAMES), IsEmpty()))

IsEqualTo

Aliases: Equals, Equal, EqualTo, IsEqual

class IsEqualTo(obj: object)

Match on an equal object.

Examples:

the_actor.should(
    See.the(Number.of(ADVERTISEMENT_BANNERS), IsEqualTo(0))
)

IsGreaterThan

Aliases: GreaterThan

class IsGreaterThan(number: float)

Match on a number that is greater than the given number.

Examples:

the_actor.should(See.the(Number.of(COUPONS), IsGreaterThan(1)))

IsGreaterThanOrEqualTo

Aliases: GreaterThanOrEqualTo

class IsGreaterThanOrEqualTo(number: float)

Match on a number that is greater than or equal to the given number.

Examples:

the_actor.should(
    See.the(Number.of(COUPONS), IsGreaterThanOrEqualTo(1))
)

IsInRange

Aliases: InRange

class IsInRange(*bounds: int | str)

Match on a number within a given range.

By default, this Resolution assumes an inclusive range (i.e. [x, y]) if no brackets are used in the range string or if numbers are used.

Examples:

the_actor.should(
    See.the(Number.of(ADVERTISEMENT_BANNERS), IsInRange(1, 5))
)

the_actor.should(
    See.the(Number.of(ADVERTISEMENT_BANNERS), IsInRange("(1, 5)"))
)

the_actor.should(See.the(Number.of(PUPPY_PICTURES), IsInRange("1-5")))

the_actor.should(See.the(Number.of(COOKIES), IsInRange("[1, 5)")))

IsLessThan

Aliases: LessThan

class IsLessThan(number: float)

Match on a number that is less than the given number.

Examples:

the_actor.should(
    See.the(Number.of(ADVERTISEMENT_POPUPS), IsLessThan(1))
)

IsLessThanOrEqualTo

Aliases: LessThanOrEqualTo

class IsLessThanOrEqualTo(number: float)

Match on a number that is less than or equal to the given number.

Examples:

the_actor.should(
    See.the(Number.of(VOUCHER_INPUTS), IsLessThanOrEqualTo(1))
)

IsNot

Aliases: DoesNot, DoNot

class IsNot(resolution: Resolvable)

Match a negated Resolution.

Examples:

the_actor.should(See.the(Element(WELCOME_BANNER), IsNot(Visible())))

Matches

Aliases: Match

class Matches(pattern: str)

Match a string using a regular expression.

Examples:

the_actor.should(
    # matches "/product/1", "/product/22", "/product/942"...
    See.the(Text.of_the(URL), Matches(r"/product/[0-9]{1,3}"))
)

ReadsExactly

Aliases: ReadExactly

class ReadsExactly(text: str)

Match a specific string exactly.

Examples:

the_actor.should(
    See.the(Text.of_the(LOGIN_MESSAGE), ReadsExactly("Log in below."))
)

StartsWith

Aliases: StartWith

class StartsWith(prefix: str)

Match a string which starts with the given substring.

Examples:

the_actor.should(
    See.the(Text.of_the(WELCOME_MESSAGE), StartsWith("Welcome"))
)

BaseResolution

class BaseResolution(*args: object, **kwargs: object)

Base class for Resolutions, ScreenPy’s “expected value”.

An abstraction barrier for PyHamcrest’s matchers. Allows for natural language assertions and hooks into ScreenPy’s logging framework.

You probably shouldn’t expect to call any of the defined methods on this class or any inherited classes. Just pass an instantiated Resolution to your Actor, they’ll know what to do with it.