def test_loader(self): loader = Loader() fm = OpenStruct(loader=loader) SettingsAware.settings = Fake() FileManagerAware.fm = fm # initially, the loader has nothing to do self.assertFalse(loader.has_work()) dir = Directory(TESTDIR) self.assertEqual(None, dir.files) self.assertFalse(loader.has_work()) # Calling load_content() will enqueue the loading operation. # dir is not loaded yet, but the loader has work dir.load_content(schedule=True) self.assertEqual(None, dir.files) self.assertTrue(loader.has_work()) iterations = 0 while loader.has_work(): iterations += 1 loader.work() #print(iterations) self.assertNotEqual(None, dir.files) self.assertFalse(loader.has_work())
class benchmark_load(object): def __init__(self): self.loader = Loader() fm = OpenStruct(loader=self.loader) SettingsAware.settings = Fake() FileManagerAware.fm = fm self.dir = Directory(TESTDIR) def bm_run(self, n): for _ in range(n): self.dir.load_content(schedule=True) while self.loader.has_work(): self.loader.work()