Commit c57833da by Calen Pennington

Define equality for XModuleDescriptors

parent f035d560
......@@ -3,6 +3,7 @@ from lxml import etree
from xmodule.mako_module import MakoModuleDescriptor
from xmodule.xml_module import XmlDescriptor
class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
"""
Module that provides a raw editing view of it's data and children
......
......@@ -37,5 +37,6 @@ class CustomTagModule(XModule):
def get_html(self):
return self.html
class CustomTagDescriptor(RawDescriptor):
module_class = CustomTagModule
......@@ -213,6 +213,10 @@ class XModuleDescriptor(Plugin):
# A list of metadata that this module can inherit from its parent module
inheritable_metadata = ('graded', 'due', 'graceperiod', 'showanswer', 'rerandomize')
# A list of descriptor attributes that must be equal for the discriptors to be
# equal
equality_attributes = ('definition', 'metadata', 'location', 'shared_state_key', '_inherited_metadata')
# ============================= STRUCTURAL MANIPULATION ===========================
def __init__(self,
system,
......@@ -395,6 +399,27 @@ class XModuleDescriptor(Plugin):
"""
raise NotImplementedError("get_html() must be provided by specific modules")
# =============================== BUILTIN METHODS ===========================
def __eq__(self, other):
eq = (self.__class__ == other.__class__ and
all(getattr(self, attr, None) == getattr(other, attr, None)
for attr in self.equality_attributes))
if not eq:
for attr in self.equality_attributes:
print getattr(self, attr, None), getattr(other, attr, None), getattr(self, attr, None) == getattr(other, attr, None)
return eq
def __repr__(self):
return "{class_}({system!r}, {definition!r}, location={location!r}, metadata={metadata!r})".format(
class_=self.__class__.__name__,
system=self.system,
definition=self.definition,
location=self.location,
metadata=self.metadata
)
class DescriptorSystem(object):
def __init__(self, load_item, resources_fs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment