[h5py] 398/455: Fix broken object comparison

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit aa3ba14530eb00bc9ab6b143c93f7b305b0acc81
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Feb 9 02:44:25 2010 +0000

    Fix broken object comparison
---
 h5py/highlevel.py                |  2 ++
 h5py/tests/high/test_hlobject.py | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index a2bf178..a7c369d 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -141,6 +141,8 @@ class HLObject(object):
         if hasattr(other, 'id'):
             return self.id == other.id
         return False
+    def __ne__(self, other):
+        return not self.__eq__(other)
 
 class _DictCompat(object):
 
diff --git a/h5py/tests/high/test_hlobject.py b/h5py/tests/high/test_hlobject.py
index 94b4c61..cbe362a 100644
--- a/h5py/tests/high/test_hlobject.py
+++ b/h5py/tests/high/test_hlobject.py
@@ -18,6 +18,28 @@ class Base(tests.HTest):
             if self.name and os.path.exists(self.name):
                 os.unlink(self.name)
 
+class TestComparison(Base):
+
+    def test_eq(self):
+        """ (HLObject) __eq__ and __ne__ are opposite (files and groups) """
+        g1 = self.f.create_group('a')
+        g2 = self.f['a']
+        g3 = self.f.create_group('b')
+        f1 = self.f
+        f2 = g1.file
+        self.assert_(g1 == g2)
+        self.assert_(not g1 != g2)
+        self.assert_(g1 != g3)
+        self.assert_(not g1 == g3)
+        self.assert_(f1 == f2)
+        self.assert_(not f1 != f2)
+        
+    def test_grp(self):
+        """ (HLObject) File objects don't compare equal to root group """
+        g = self.f['/']
+        self.assert_(not g == self.f)
+        self.assert_(g != self.f)
+
 class TestPropFile(Base):
 
     def test_file2(self):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list