Updates for struct to pass unit tests

This commit is contained in:
Doug Blank 2015-01-02 17:28:38 -05:00
parent 1f8aa6917f
commit dcea49c2a7
2 changed files with 6 additions and 3 deletions

View File

@ -91,7 +91,7 @@ class TagCheck(unittest.TestCase, BaseCheck):
class DatabaseCheck(unittest.TestCase): class DatabaseCheck(unittest.TestCase):
maxDiff = None maxDiff = None
def generate_test(obj): def generate_case(obj):
""" """
Dynamically generate tests and attach to DatabaseCheck. Dynamically generate tests and attach to DatabaseCheck.
""" """
@ -111,7 +111,7 @@ db = import_as_dict("example/gramps/example.gramps", User())
for table in db._tables.keys(): for table in db._tables.keys():
for handle in db._tables[table]["handles_func"](): for handle in db._tables[table]["handles_func"]():
obj = db._tables[table]["handle_func"](handle) obj = db._tables[table]["handle_func"](handle)
generate_test(obj) generate_case(obj)
class StructTest(unittest.TestCase): class StructTest(unittest.TestCase):
def test(self): def test(self):
@ -120,7 +120,7 @@ class StructTest(unittest.TestCase):
self.assertEqual(s["gramps_id"], "F0001") self.assertEqual(s["gramps_id"], "F0001")
s["gramps_id"] = "TEST" s["gramps_id"] = "TEST"
self.assertEqual(s["gramps_id"], "TEST") self.assertEqual(s["gramps_id"], "TEST")
self.assertEqual(s["father_handle.primary_name.first_name"], self.assertEqual(s.father_handle.primary_name.first_name,
"Allen Carl") "Allen Carl")
s["father_handle.primary_name.first_name"] = "Edward" s["father_handle.primary_name.first_name"] = "Edward"
self.assertEqual(s["father_handle.primary_name.first_name"], self.assertEqual(s["father_handle.primary_name.first_name"],

View File

@ -384,6 +384,9 @@ class Struct(object):
else: else:
self.transaction = None self.transaction = None
def __setitem__(self, item, value):
self.struct[item] = value
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, Struct): if isinstance(other, Struct):
return self.struct == other.struct return self.struct == other.struct