From af04e57c2b8efcaf79b5ac778f7f649d28122d2c Mon Sep 17 00:00:00 2001 From: Petr Šplíchal Date: Wed, 29 Jun 2011 11:13:00 +0200 Subject: Nitrate: Provide default equality handling for all objects --- Nitrate.py | 61 +++++++++++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/Nitrate.py b/Nitrate.py index cd4257b..0a6d9a1 100644 --- a/Nitrate.py +++ b/Nitrate.py @@ -167,6 +167,13 @@ class Nitrate(object): # Nitrate Properties # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + id = property(_getter("id"), doc="Object identifier.") + + @property + def identifier(self): + """ Consistent identifier string. """ + return "{0}#{1}".format(self._prefix, self._id) + @property def _config(self): """ User configuration (expected in ~/.nitrate). """ @@ -203,12 +210,6 @@ class Nitrate(object): Nitrate._requests += 1 return Nitrate._connection - @property - def identifier(self): - """ Consistent identifier string. """ - return "{0}#{1}".format(self._prefix, self._id) - - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Nitrate Special # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -229,6 +230,22 @@ class Nitrate(object): return "Nitrate server: {0}\nTotal requests handled: {1}".format( self._config["url"], self._requests) + def __eq__(self, other): + """ Handle object equality based on its id. """ + return self.id == other.id + + def __ne__(self, other): + """ Handle object inequality based on its id. """ + return self.id != other.id + + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Nitrate Methods + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + def _get(self): + """ Fetch object data from the server. """ + raise NitrateError("To be implemented by respective class") + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Bug Class @@ -364,14 +381,6 @@ class PlanType(Nitrate): """ Return TestPlan type for printing. """ return self.name - def __eq__(self, other): - """ Handle correctly TestPlan type equality. """ - return self._id == other._id - - def __ne__(self, other): - """ Handle correctly TestPlan type inequality. """ - return self._id != other._id - @property def id(self): """ Numeric TestPlan type id. """ @@ -414,14 +423,6 @@ class Priority(Nitrate): """ Return priority name for printing. """ return self.name - def __eq__(self, other): - """ Handle correctly priority equality. """ - return self._id == other._id - - def __ne__(self, other): - """ Handle correctly priority inequality. """ - return self._id != other._id - @property def id(self): """ Numeric priority id. """ @@ -569,14 +570,6 @@ class CaseStatus(Nitrate): """ Return casestatus name for printing. """ return self.name - def __eq__(self, other): - """ Handle correctly casestatus equality. """ - return self._id == other._id - - def __ne__(self, other): - """ Handle correctly casestatus inequality. """ - return self._id != other._id - @property def id(self): """ Numeric casestatus id. """ @@ -622,14 +615,6 @@ class Status(Nitrate): """ Return status name for printing. """ return self.name - def __eq__(self, other): - """ Handle correctly status equality. """ - return self._id == other._id - - def __ne__(self, other): - """ Handle correctly status inequality. """ - return self._id != other._id - @property def id(self): """ Numeric status id. """ -- cgit