def testEveryDo(self): result=[0] def addOne(): result[0] += 1 action = every_do(2, addOne) action() self.assertEqual(0, result[0]) action() self.assertEqual(1, result[0]) action() self.assertEqual(1, result[0]) action() self.assertEqual(2, result[0])
def main(): with open('../../data/itunes_library.xml','r') as stream: parser = TracksParser(stream) def commit(store): store.commit() print "commit" name='../../data/store.db' if os.path.isfile(name): os.remove(name) with store.DomainStore(name) as storage: do_commit=every_do(1024, lambda: commit(storage)) storage.create_meta() for track in parser: domain.Song(track).save() do_commit()