[tahoe-lafs-trac-stream] [tahoe-lafs] #1881: test utility for comparing sets

tahoe-lafs trac at tahoe-lafs.org
Fri Nov 30 01:56:00 UTC 2012


#1881: test utility for comparing sets
----------------------------+--------------------------
     Reporter:  davidsarah  |      Owner:  davidsarah
         Type:  defect      |     Status:  assigned
     Priority:  minor       |  Milestone:  undecided
    Component:  code        |    Version:  1.9.2
   Resolution:              |   Keywords:  test cleanup
Launchpad Bug:              |
----------------------------+--------------------------
Changes (by davidsarah):

 * status:  new => assigned


Old description:

> From [https://github.com/zooko/tahoe-
> lafs/commit/73d5a059bda6cf5a9c484a6af332d764069b0ba1], re: this code
> {{{
>     responding_set = frozenset([s.get_serverid() for s in
> prr.get_servers_responding()])
>     self.failIf(expected - responding_set, expected - responding_set)
>     self.failIf(responding_set - expected, responding_set - expected)
>     self.failUnlessEqual(expected,
>                          set([s.get_serverid()
>                               for s in prr.get_servers_responding()]))
> }}}
>
> How about we add a mixin that allows us to write:
> {{{
> self.failUnlessEqualSets([s.get_serverid() for s in
> prr.get_servers_responding()], self.g.get_all_serverids())
> }}}
> e.g.
> {{{
> class TestUtilMixin:  # might merge with ReallyEqualMixin, etc.
>     def failUnlessEqualSets(self, actual, expected):
>         actual_set = set(actual)
>         expected_set = set(expected)
>         self.failUnlessEqual(actual_set, expected_set,
>                              ("\nexpected - actual = %r"
>                               "\nactual - expected = %r")
>                              % (expected_set - actual_set, actual_set -
> expected_set))
> }}}
>
> There are quite a few cases in the tests that could use this.

New description:

 From [https://github.com/zooko/tahoe-
 lafs/commit/73d5a059bda6cf5a9c484a6af332d764069b0ba1], re: this code
 {{{
     responding_set = frozenset([s.get_serverid() for s in
 prr.get_servers_responding()])
     self.failIf(expected - responding_set, expected - responding_set)
     self.failIf(responding_set - expected, responding_set - expected)
     self.failUnlessEqual(expected,
                          set([s.get_serverid()
                               for s in prr.get_servers_responding()]))
 }}}

 How about we add a mixin that allows us to write:
 {{{
 self.failUnlessEqualSets([s.get_serverid() for s in
 prr.get_servers_responding()],
                          self.g.get_all_serverids())
 }}}
 e.g.
 {{{
 class TestUtilMixin:  # might merge with ReallyEqualMixin, etc.
     def failUnlessEqualSets(self, actual, expected):
         actual_set = set(actual)
         expected_set = set(expected)
         self.failUnlessEqual(actual_set, expected_set,
                              ("\nexpected - actual = %r"
                               "\nactual - expected = %r")
                              % (expected_set - actual_set, actual_set -
 expected_set))
 }}}

 There are quite a few cases in the tests that could use this.

--

-- 
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/1881#comment:1>
tahoe-lafs <https://tahoe-lafs.org>
secure decentralized storage


More information about the tahoe-lafs-trac-stream mailing list