← Back to team overview

launchpad-dev team mailing list archive

Re: Reminder about a great Testtools matcher

 

On Tue, Jul 19, 2011 at 1:11 PM, Julian Edwards
<julian.edwards@xxxxxxxxxxxxx> wrote:
> I hope you all have the documents for Testtools[1] matchers on speed dial
> because they are awesome.  I thought I'd remind you about the MatchesStructure
> matcher because I used it a while ago, forgot about it, and re-discovered it
> recently.
>

Thanks for the kind words, I like matchers a lot too. Props to Rob for
putting them into testtools in the first place, and Michael for adding
MatchesStructure.

...
> +        self.assertThat(copy_job, MatchesStructure(
> +            package_name=Equals(source_name),
> +            package_version=Equals(version),
> +            target_archive=Equals(target_archive),
> +            source_archive=Equals(source_archive),
> +            target_distroseries=Equals(to_series),
> +            target_pocket=Equals(to_pocket),
> +            include_binaries=Equals(False),
> +            copy_policy=Equals(PackageCopyPolicy.INSECURE)))
>

Nice. Inspired me to hack up
<https://code.launchpad.net/~jml/testtools/structure-from-dict/+merge/68409>,
which would allow you to write this instead::

self.assertThat(
    copy_job, MatchesStructure.byEquality(
        package_name=source_name,
        package_version=version,
        target_archive=target_archive,
        source_archive=source_archive,
        target_distroseries=to_series,
        target_pocket=to_pocket,
        include_binaries=False,
        copy_policy=PackageCopyPolicy.INSECURE))

jml


References