Ticket #11236: trac_11236-test_eq_for_python_2_7-nt.patch

File trac_11236-test_eq_for_python_2_7-nt.patch, 3.1 KB (added by nthiery, 10 years ago)
  • sage/structure/element.pyx

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1303550807 14400
    # Node ID af7d60cb6267b17d213291b26244dc4576f94923
    # Parent  41ab36bc87a30721b512a0cc1418183e0ec247d3
    #11236: Fix _test_eq for Python 2.7
    
    diff --git a/sage/structure/element.pyx b/sage/structure/element.pyx
    a b cdef class Element(sage_object.SageObjec 
    517517            sage: CCls(Parent())._test_eq()
    518518            Traceback (most recent call last):
    519519            ...
    520             AssertionError: Generic element of a structure == None
     520            AssertionError: broken equality: Generic element of a structure == None
    521521
    522522        Let us now break inequality::
    523523
    cdef class Element(sage_object.SageObjec 
    530530            AssertionError: broken non-equality: Generic element of a structure != itself
    531531        """
    532532        tester = self._tester(**options)
    533         tester.assertEqual(self, self)
    534         tester.assertNotEqual(self, None)
     533        # We don't use assertEqual / assertNonEqual in order to be
     534        # 100% sure we indeed call the operators == and !=, whatever
     535        # the version of Python is (see #11236)
     536        tester.assertTrue(self == self,
     537                   LazyFormat("broken equality: %s == itself is False")%self)
     538        tester.assertFalse(self == None,
     539                   LazyFormat("broken equality: %s == None")%self)
    535540        tester.assertFalse(self != self,
    536541                           LazyFormat("broken non-equality: %s != itself")%self)
    537542        tester.assertTrue(self != None,
  • sage/structure/parent.pyx

    diff --git a/sage/structure/parent.pyx b/sage/structure/parent.pyx
    a b cdef class Parent(category_object.Catego 
    634634            sage: CCls()._test_eq()
    635635            Traceback (most recent call last):
    636636            ...
    637             AssertionError: <class '__main__.CCls'> == None
     637            AssertionError: broken equality: <class '__main__.CCls'> == None
    638638
    639639        Let us now break inequality::
    640640
    cdef class Parent(category_object.Catego 
    647647            AssertionError: broken non-equality: <class '__main__.CCls'> != itself
    648648        """
    649649        tester = self._tester(**options)
    650         tester.assertEqual(self, self)
    651         tester.assertNotEqual(self, None)
     650
     651        # We don't use assertEqual / assertNonEqual in order to be
     652        # 100% sure we indeed call the operators == and !=, whatever
     653        # the version of Python is (see #11236)
     654        tester.assertTrue(self == self,
     655                   LazyFormat("broken equality: %s == itself is False")%self)
     656        tester.assertFalse(self == None,
     657                   LazyFormat("broken equality: %s == None")%self)
    652658        tester.assertFalse(self != self,
    653659                   LazyFormat("broken non-equality: %s != itself")%self)
    654660        tester.assertTrue(self != None,
    655                    LazyFormat("broken non-equality: %s is not != None")%self)
     661                   LazyFormat("broken non-equality: %s != None is False")%self)
    656662
    657663    cdef int init_coerce(self, bint warn=True) except -1:
    658664        if self._coerce_from_hash is None: