I ran the following code tonight and ran into some problems. I hope that this solution will help others:
Trinity:marriage_test kelvin$ python marriage.py F ====================================================================== FAIL: testEquality (__main__.equalityTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "marriage.py", line 24, in testEquality self.assertEqual(a, b, "Marriages not equal") AssertionError: Marriages not equal ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) Trinity:marriage_test kelvin$ |
This is the test that was failing:
class equalityTests(unittest.TestCase): def testEquality(self): a = OppositeSexMarriage() b = SameSexMarriage() self.assertEqual(a, b, "Marriages not equal") |
Fortunately the fix is straightforward (base Marriage on GoodLegislation):
class GoodLegislation(object): def __eq__(self, other): return self.__dict__ == other.__dict__ class Marriage(GoodLegislation): pass |
This is the result that we were after:
Trinity:marriage_test kelvin$ python marriage.py . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Trinity:marriage_test kelvin$ |
Congratulations to the good people of New York state. They became the sixth state to allow same-sex marriage.
Code available here!