item fields no longer dirtied if unchanged when assigned

This is especially important for read(), which will assign many times while, in many cases, causing few actual changes. A store() that follows soon after will now be much more lightweight.

--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%4079
This commit is contained in:
adrian.sampson 2008-07-09 21:44:15 +00:00
parent e811b72763
commit fb4344e937
2 changed files with 9 additions and 3 deletions

View file

@ -121,8 +121,10 @@ class Item(object):
Otherwise, performs an ordinary setattr."""
if key in item_keys:
self.record[key] = value
self.dirty[key] = True
if (not (key in self.record)) or (self.record[key] != value):
# don't dirty if value unchanged
self.record[key] = value
self.dirty[key] = True
else:
object.__setattr__(self, key, value)

View file

@ -117,8 +117,12 @@ class GetSetTest(unittest.TestCase):
self.assertEqual(self.i.bpm, 4915)
def test_set_sets_dirty_flag(self):
self.i.comp = True
self.i.comp = not self.i.comp
self.assertTrue(self.i.dirty['comp'])
def test_set_does_not_dirty_if_value_unchanged(self):
self.i.title = self.i.title
self.assertTrue(not self.i.dirty['title'])
class DestinationTest(unittest.TestCase):
def setUp(self):