← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1586268] Re: Unit test: self.assertNotEqual in unit.test_base.BaseTest.test_eq does not work in PY2

 

Reviewed:  https://review.openstack.org/337445
Committed: https://git.openstack.org/cgit/openstack/python-smaugclient/commit/?id=7b16de4908371cad5c1544551132eac34758315f
Submitter: Jenkins
Branch:    master

commit 7b16de4908371cad5c1544551132eac34758315f
Author: yuyafei <yu.yafei@xxxxxxxxxx>
Date:   Tue Jul 5 15:37:56 2016 +0800

    Add __ne__ built-in function
    
    In Python 3 __ne__ by default delegates to __eq__ and inverts the
    result, but in Python 2 they urge you to define __ne__ when you
    define __eq__ for it to work properly [1].There are no implied
    relationships among the comparison operators. The truth of x==y
    does not imply that x!=y is false. Accordingly, when defining
    __eq__(), one should also define __ne__() so that the operators
    will behave as expected.
    [1]https://docs.python.org/2/reference/datamodel.html#object.__ne__
    
    Change-Id: Iae22095146e64081f362601665284b43d0056f48
    Closes-Bug: #1586268


** Changed in: python-smaugclient
       Status: In Progress => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1586268

Title:
  Unit test: self.assertNotEqual in  unit.test_base.BaseTest.test_eq
  does not work in PY2

Status in Ceilometer:
  Fix Released
Status in daisycloud-core:
  New
Status in heat:
  New
Status in OpenStack Dashboard (Horizon):
  New
Status in keystonemiddleware:
  New
Status in neutron:
  In Progress
Status in OpenStack Compute (nova):
  In Progress
Status in python-barbicanclient:
  New
Status in python-ceilometerclient:
  Fix Released
Status in python-cinderclient:
  Fix Released
Status in python-congressclient:
  In Progress
Status in python-glanceclient:
  In Progress
Status in python-heatclient:
  Fix Released
Status in python-keystoneclient:
  In Progress
Status in python-manilaclient:
  New
Status in python-muranoclient:
  Fix Released
Status in python-novaclient:
  Fix Released
Status in python-smaugclient:
  Fix Released
Status in python-troveclient:
  In Progress
Status in tempest:
  In Progress

Bug description:
  Version: master(20160527)

  In case cinderclient.tests.unit.test_base.BaseTest.test_eq self.assertNotEqual does not work.
  Class base.Resource defines __eq__() built-in function, but does not define __ne__() built-in function, so self.assertEqual works but self.assertNotEqual does not work at all in this test case.

  steps:
  1 Clone code of python-cinderclient from master.
  2 Modify the case of unit test: cinderclient/tests/unit/test_base.py
    line50--line62.
      def test_eq(self):
          # Two resources with same ID: never equal if their info is not equal
          r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
          r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
          self.assertNotEqual(r1, r2)

          # Two resources with same ID: equal if their info is equal
          r1 = base.Resource(None, {'id': 1, 'name': 'hello'})
          r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
          # self.assertEqual(r1, r2)
          self.assertNotEqual(r1, r2)

          # Two resoruces of different types: never equal
          r1 = base.Resource(None, {'id': 1})
          r2 = volumes.Volume(None, {'id': 1})
          self.assertNotEqual(r1, r2)

          # Two resources with no ID: equal if their info is equal
          r1 = base.Resource(None, {'name': 'joe', 'age': 12})
          r2 = base.Resource(None, {'name': 'joe', 'age': 12})
          # self.assertEqual(r1, r2)
          self.assertNotEqual(r1, r2)

     Modify self.assertEqual(r1, r2) to self.assertNotEqual(r1, r2).

  3 Run unit test, and return success.

  After that, I make a test:

  class Resource(object):
      def __init__(self, person):
          self.person = person

      def __eq__(self, other):
          return self.person == other.person

  r1 = Resource("test")
  r2 = Resource("test")
  r3 = Resource("test_r3")
  r4 = Resource("test_r4")

  print r1 != r2
  print r1 == r2
  print r3 != r4
  print r3 == r4

  The result is :
  True
  True
  True
  False

  Whether r1 is precisely the same to r2 or not, self.assertNotEqual(r1,
  r2) return true.So I think self.assertNotEqual doesn't work at all in
  python2 and  should be modified.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ceilometer/+bug/1586268/+subscriptions