* add a simple metaclass for testing automatic structure equivalence

using dict, called autoeq
* fix: use autoeq to implement the structural equivalence test in xmlfiletests
This commit is contained in:
Eray Özkural
2005-11-02 17:09:15 +00:00
parent f5b5bec894
commit ddb39ad642
3 changed files with 20 additions and 4 deletions
+13 -2
View File
@@ -23,6 +23,17 @@ class autosuper(type):
class autosuprop(autosuper, autoprop):
pass
class autoeq(type):
"useful for structures"
def __init__(cls, name, bases, dict):
super(autoeq, cls).__init__(name, bases, dict)
def equal(self, other):
return self.__dict__ == other.__dict__
cls.__eq__ = equal
class Struct:
def __init__(self, **entries): self.__dict__.update(entries)
__metaclass__ = autoeq
def __init__(self, **entries):
self.__dict__.update(entries)
+1 -1
View File
@@ -143,7 +143,7 @@ class Writer(formatter.DumbWriter):
self.atbreak = 0
class autoxml(oo.autosuper):
class autoxml(oo.autosuper, oo.autoprop, oo.autoeq):
"""High-level automatic XML transformation interface for xmlfile.
The idea is to declare a class for each XML tag. Inside the
class the tags and attributes nested in the tag are further
+6 -1
View File
@@ -87,6 +87,11 @@ class AutoXmlTestCase(testcase.TestCase):
a.write('/tmp/a2.xml')
a2 = self.A()
a2.read('/tmp/a2.xml')
self.assertEqual(a, a2)
self.assertEqual(a.name, a2.name)
self.assertEqual(a.email, a2.email)
self.assertEqual(a.description, a2.description)
self.assertEqual(a.comment, a2.comment)
self.assertEqual(a.href, a2.href)
self.assertEqual(a.otherInfo, a2.otherInfo)
suite = unittest.makeSuite(AutoXmlTestCase)