You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Liu Wang <li...@google.com> on 2020/02/25 18:24:52 UTC
Are there extra Beam Python test matchers available?
Hi,
As far as I know, the matchers I can use with assert_that are
equal_to and matches_all in this file:
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/testing/util.py
Is there any matcher that I can test a PCollection contains a subset?
Is there any matcher that I can test a PCollection contains any number of a specific element?
For example, I want to test the PCollection [1, 3, 6, 10, 15, 15, 15] contains [1, 3, 6, 10], and it contains any number of 15s.
Thanks,
Liu
Re: Are there extra Beam Python test matchers available?
Posted by Kamil Wasilewski <ka...@polidea.com>.
Hi,
You can use matchers from hamcrest module. For example, assuming your
pcollection consists of a single list, you can use something like this to
test if it contains a subset:
import hamcrest as hc
assert_that(pcoll, matches_all([hc.has_items(1, 3, 6, 10)]))
Thanks,
Kamil
On Tue, Feb 25, 2020 at 7:24 PM Liu Wang <li...@google.com> wrote:
> Hi,
>
> As far as I know, the matchers I can use with assert_that are
> equal_to and matches_all in this file:
>
> https://github.com/apache/beam/blob/master/sdks/python/apache_beam/testing/util.py
>
> Is there any matcher that I can test a PCollection contains a subset?
> Is there any matcher that I can test a PCollection contains any number of
> a specific element?
>
> For example, I want to test the PCollection [1, 3, 6, 10, 15, 15, 15]
> contains [1, 3, 6, 10], and it contains any number of 15s.
>
> Thanks,
> Liu
>