From 308f4fdc17fb9937547663fda7e229a572422651 Mon Sep 17 00:00:00 2001
From: Mitchel Humpherys <mitchelh@codeaurora.org>
Date: Fri, 11 Apr 2014 11:05:56 -0700
Subject: [PATCH] lrdp-v2: define equivalency for Register objects

Register objects are `equal' if they have the same fields and the values
of all of those fields are equal. Overload Register.__eq__ to reflect
this.

Change-Id: I680e869470b20d6dc88d4bd78da9f002980aea4f
---
 linux-ramdump-parser-v2/register.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/linux-ramdump-parser-v2/register.py b/linux-ramdump-parser-v2/register.py
index 03e47fc..bba985d 100644
--- a/linux-ramdump-parser-v2/register.py
+++ b/linux-ramdump-parser-v2/register.py
@@ -130,6 +130,29 @@ class Register(object):
         # infinite recursion to __setattr__
         object.__setattr__(self, 'value', val)
 
+    def __eq__(self, other):
+        """Two Register objects are defined to be equal if they have the same
+        fields and all of those fields have the same values.
+
+        >>> r1 = Register(0xf, top=(7, 4), bottom=(3, 0))
+        >>> r2 = Register(0, top=(7, 4), bottom=(3, 0))
+        >>> r1 == r2
+        False
+        >>> r2.bottom = 0xf
+        >>> r1 == r2
+        True
+        >>> r2.top = 0xf
+        >>> r1 == r2
+        False
+
+        """
+        if self._regs != other._regs:
+            return False
+        for r in self._regs:
+            if getattr(self, r) != getattr(other, r):
+                return False
+        return True
+
     def __repr__(self):
         if self.value is None:
             return 'value: None'
-- 
GitLab