facebook / TestSlide

A Python test framework
https://github.com/facebook/TestSlide
MIT License
146 stars 54 forks source link

Request: Container Matchers #346

Closed bpjatfb closed 1 year ago

bpjatfb commented 1 year ago

The current container matchers only cover list and dict (TestSlide docs). Unfortunately, this doesn't help much when I'm working with other containers or iterables (of which, Python has many!). I am proposing that we add matchers for arbitrary containers as well. Something like the following, although the names could probably be improved:

Example

Actual value (a dict of deque):

{
    'a': deque([1, 2, 3], maxlen=100),
    'b': deque([4, 5, 6], maxlen=100),
    'c': deque([7, 8, 9], maxlen=100),
}

Since maxlen=100 isn't a hard requirement, I don't really want to specify it in my test. It would be really great if I could test like so:

{
    'a': AnyIterableContainingAll([1, 2, 3]),
    'b': AnyIterableContainingAll([4, 5, 6]),
    'c': AnyIterableContainingAll([7, 8, 9]),
}

See also

fornellas commented 1 year ago

LPGTM @bpjatfb, how do you feel abotu cutting a PR to add these matches here and some tests here?

bpjatfb commented 1 year ago

how do you feel abotu cutting a PR to add these matches here and some tests here?

Thanks for the code pointers! I'll put together a PR for these.

bpjatfb commented 1 year ago

Fixed by #350