From 836dea135b73c2b0e802888702c6b67c86f2bea4 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 4 Jan 2010 05:36:34 +0100 Subject: Introduce equality and inequality tests --- layman/overlay.py | 9 +++++++++ layman/overlays/cvs.py | 8 ++++++++ layman/overlays/overlay.py | 10 ++++++++++ layman/overlays/tar.py | 10 ++++++++++ 4 files changed, 37 insertions(+) diff --git a/layman/overlay.py b/layman/overlay.py index ae19f28..643e652 100644 --- a/layman/overlay.py +++ b/layman/overlay.py @@ -84,6 +84,15 @@ class Overlays: if os.path.exists(path): self.read_file(path) + def __eq__(self, other): + for key in set(self.overlays.keys() + other.overlays.keys()): + if self.overlays[key] != other.overlays[key]: + return False + return True + + def __ne__(self, other): + return not self.__eq__(other) + def read_file(self, path): '''Read the overlay definition file.''' diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py index a4ff74d..a9c4f0f 100644 --- a/layman/overlays/cvs.py +++ b/layman/overlays/cvs.py @@ -48,6 +48,14 @@ class CvsOverlay(Overlay): else: self.subpath = '' + def __eq__(self, other): + res = super(CvsOverlay, self).__eq__(other) \ + and self.subpath == other.subpath + return res + + def __ne__(self, other): + return not self.__eq__(other) + def add(self, base, quiet = False): '''Add overlay.''' diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py index 8e1abc2..aa20f9d 100644 --- a/layman/overlays/overlay.py +++ b/layman/overlays/overlay.py @@ -147,6 +147,16 @@ class Overlay(object): else: self.homepage = None + def __eq__(self, other): + for i in ('description', 'homepage', 'name', 'owner_email', + 'owner_name', 'priority', 'src', 'status'): + if getattr(self, i) != getattr(other, i): + return False + return True + + def __ne__(self, other): + return not self.__eq__(other) + def set_priority(self, priority): '''Set the priority of this overlay.''' diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py index 2ef69af..d65befc 100644 --- a/layman/overlays/tar.py +++ b/layman/overlays/tar.py @@ -88,6 +88,16 @@ class TarOverlay(Overlay): else: self.category = '' + def __eq__(self, other): + res = super(TarOverlay, self).__eq__(other) \ + and self.format == other.format \ + and self.subpath == other.subpath \ + and self.category == other.category + return res + + def __ne__(self, other): + return not self.__eq__(other) + def add(self, base, quiet = False): '''Add overlay.''' -- cgit v1.2.3-1-g7c22