#1881 assigned defect

test utility for comparing sets

Reported by: davidsarah Owned by: davidsarah
Priority: minor Milestone: undecided
Component: code Version: 1.9.2
Keywords: test cleanup Cc: zooko
Launchpad Bug:

Description (last modified by davidsarah)

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.

Change History (2)

comment:1 Changed at 2012-11-30T01:56:00Z by davidsarah

  • Description modified (diff)
  • Status changed from new to assigned

comment:2 Changed at 2012-11-30T14:49:07Z by zooko

  • Cc zooko added
Note: See TracTickets for help on using tickets.