vrindisbacher / python-property-based-testing

Property Based Testing in Python
MIT License
1 stars 0 forks source link

Implement "interfaces" using TypedDict #25

Open vrindisbacher opened 1 year ago

vrindisbacher commented 1 year ago

Many tests using things like dictionaries need a very specific set of keys, or set of results.

Interfaces should provide a solution to this, through a mechanism supporting specific generation of objects as input into the function. This should aim to alleviate the burden of creating generators.

The way to do this is to leverage typing's TypedDict.

class Point2D(TypedDict):
    x: int
    y: int
    label: str

a: Point2D = {'x': 1, 'y': 2, 'label': 'good'}  # OK

The user should also be able to directly provide a value for their class attribute.