lundi 29 janvier 2018

Different return to __cmp__ override in Python

I am writing some test cases to a __cmp_ Python override. My code looks like this:

def __cmp__(self, other):
    if self.name == other.name: 
        return 0
    return -1

When I test this way:

self.assertEqual(0, first_tail > first_tail)
self.assertEqual(0, first_tail < first_tail)

The test answers OK. But when I try:

self.assertEqual(0, first_tail == first_tail)

I get this error:

True != 0

Expected :0
Actual   :True

Aucun commentaire:

Enregistrer un commentaire