summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Makkar <tushar@codenation.co.in>2016-09-22 19:33:53 +0530
committerTushar Makkar <tushar@codenation.co.in>2016-09-22 19:33:53 +0530
commitadeb05b055259d74d8b30e1f25b693445b730fcb (patch)
tree4f8f9ab5005915a6a949cca2aa32969b6e7c2752
parent79d7ed825d2b19dbb3140b3caa88637e769e31d4 (diff)
downloadvoluptuous-adeb05b055259d74d8b30e1f25b693445b730fcb.tar.gz
Adding eq for schemas
-rw-r--r--voluptuous/schema_builder.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/voluptuous/schema_builder.py b/voluptuous/schema_builder.py
index 8f93863..c0f5a19 100644
--- a/voluptuous/schema_builder.py
+++ b/voluptuous/schema_builder.py
@@ -153,6 +153,21 @@ class Schema(object):
Nodes can be values, in which case a direct comparison is used, types,
in which case an isinstance() check is performed, or callables, which will
validate and optionally convert the value.
+
+ We can equate schemas also.
+
+ For Example:
+
+ >>> class Structure(object):
+ ... def __init__(self, one=None, three=None):
+ ... self.one = one
+ ... self.three = three
+ ...
+ >>> validate = Schema(Object({'one': 'two', 'three': 'four'}, cls=Structure))
+ >>> validate1 = Schema(Object({'one': 'two', 'three': 'four'}, cls=Structure))
+ >>> assert validate1 == validate
+ >>> validate2 = Schema(Object({'one1': 'two1', 'three': 'four'}, cls=Structure))
+ >>> assert validate2 != validate
"""
_extra_to_name = {
@@ -181,6 +196,11 @@ class Schema(object):
self.extra = int(extra) # ensure the value is an integer
self._compiled = self._compile(schema)
+ def __eq__(self, other):
+ if other == self.schema:
+ return True
+ return False
+
def __repr__(self):
return "<Schema(%s, extra=%s, required=%s) object at 0x%x>" % (
self.schema, self._extra_to_name.get(self.extra, '??'),