test utility for comparing sets #1881

Open
opened 2012-11-30 01:55:33 +00:00 by davidsarah · 0 comments
davidsarah commented 2012-11-30 01:55:33 +00:00
Owner

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())

5.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.

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()) ``` 5.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.
tahoe-lafs added the
code
minor
defect
1.9.2
labels 2012-11-30 01:55:33 +00:00
tahoe-lafs added this to the undecided milestone 2012-11-30 01:55:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: tahoe-lafs/trac-2024-07-25#1881
No description provided.