[TIP] Fwd: [Launchpad-dev] Reminder about a great Testtools matcher
mbp at sourcefrog.net
Tue Jul 19 18:08:43 PDT 2011
I thought this was cool enough it might be of interest to t-i-p.
---------- Forwarded message ----------
From: Julian Edwards <julian.edwards at canonical.com>
Date: 19 July 2011 22:11
Subject: [Launchpad-dev] Reminder about a great Testtools matcher
To: Launchpad Community Development Team <launchpad-dev at lists.launchpad.net>
I hope you all have the documents for Testtools matchers on speed dial
because they are awesome. I thought I'd remind you about the
matcher because I used it a while ago, forgot about it, and re-discovered it
Check out this diff snippet:
- self.assertEqual(source_name, copy_job.package_name)
- self.assertEqual(version, copy_job.package_version)
- self.assertEqual(target_archive, copy_job.target_archive)
- self.assertEqual(source_archive, copy_job.source_archive)
- self.assertEqual(to_series, copy_job.target_distroseries)
- self.assertEqual(to_pocket, copy_job.target_pocket)
- self.assertEquals(PackageCopyPolicy.INSECURE, copy_job.copy_policy)
+ self.assertThat(copy_job, MatchesStructure(
I replaced a load of serially-processed assertions with a single assertion.
This is good because:
* It checks all of the conditions, not just up until the first one fails.
* It prints out all the values if any of them fail to match.
I hope to see more use of this pattern!
Mailing list: https://launchpad.net/~launchpad-dev
Post to : launchpad-dev at lists.launchpad.net
Unsubscribe : https://launchpad.net/~launchpad-dev
More help : https://help.launchpad.net/ListHelp
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python