#1881 assigned defect

test utility for comparing sets — at Initial Version

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

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.

Change History (0)

Note: See TracTickets for help on using tickets.