Define equality for XModuleDescriptors

This commit is contained in:
Calen Pennington
2012-07-02 12:24:19 -04:00
parent f035d5602d
commit c57833dab7
3 changed files with 27 additions and 0 deletions

View File

@@ -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

View File

@@ -37,5 +37,6 @@ class CustomTagModule(XModule):
def get_html(self):
return self.html
class CustomTagDescriptor(RawDescriptor):
module_class = CustomTagModule

View File

@@ -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):