This PR adds two new matchers, has_getter(name, matcher) and has_getters(dict[str, matcher]) and overloads, similar to has_property() and has_properties().
In fact, I forked the property matchers to create the getter matchers.
Use case
There matchers are meant for objects that expose properties via callable getter methods. Prominent examples are the Qt GUI toolkit wrappers PyQt and PySide. The Qt objects expose properties via getter/setter pairs, and the Python wrappers translate them 1:1.
Have a look at QRectF implementing a floating point rectangle, and QPointF. Object dimensions, coordinates and similar are accessible via getter methods.
The addition of has_getter() allows matching against those as if they were plain Python properties.
rect = QRectF(0, 1, 10, 11) # x, y, width, height
assert_that(
rect, has_getters({
"topLeft": has_getters({ # These return a QPointF
"x": close_to(0),
"y": close_to(1),}),
"bottomRight": has_getters({
"x": close_to(10),
"y": close_to(12),}),
"width": close_to(10),
"height": close_to(11),
"isEmpty": False,
})
This PR adds two new matchers,
has_getter(name, matcher)
andhas_getters(dict[str, matcher])
and overloads, similar tohas_property()
andhas_properties()
.In fact, I forked the property matchers to create the getter matchers.
Use case
There matchers are meant for objects that expose properties via callable getter methods. Prominent examples are the Qt GUI toolkit wrappers PyQt and PySide. The Qt objects expose properties via getter/setter pairs, and the Python wrappers translate them 1:1. Have a look at QRectF implementing a floating point rectangle, and QPointF. Object dimensions, coordinates and similar are accessible via getter methods.
The addition of has_getter() allows matching against those as if they were plain Python properties.