class TestBuildAppStandardConfig(CommonAppSuite, TestCase): def setUp(self): self.c = Configuration() self.c.runstate = RuntimeStateConfig() self.app = BuildApp(self.c) self.app.default_pool = random.choice(['serial', 'thread']) self.app.pool_size = 2 def test_conf_object_consistent_in_task(self): self.assertEqual(self.app.queue, []) t = self.app.add('task') self.assertIs(self.c, t.conf) self.assertIs(self.c, self.app.queue[0].conf) def test_conf_object_consistent_in_app(self): self.assertEqual(self.app.queue, []) self.app.add('app') self.assertIs(self.c, self.app.conf) self.assertIs(self.c, self.app.queue[0].conf) def test_conf_object_consistent_in_new_task(self): self.assertEqual(self.app.queue, []) t = Task() self.assertIsNone(t.conf) self.app.add(t) self.assertIsNotNone(t.conf) self.assertIs(self.c, self.app.queue[0].conf) self.assertIs(self.c, t.conf) def test_force_options(self): self.assertEquals(self.c.runstate.force, self.app.force) self.assertFalse(self.c.runstate.force) self.assertFalse(self.app.force) self.app._force = None self.assertFalse(self.app.force) def test_default_pool_size(self): self.assertIsNotNone(self.c) self.assertIsNotNone(self.app.conf) self.app._pool_size = None self.assertEquals(self.c.runstate.pool_size, self.app.pool_size) def tearDown(self): self.app.close_pool()
def test_single_runner_app(self): self.assertEqual(self.app.queue, []) self.assertEqual(self.app.results, []) app = BuildApp() app.pool_size = 2 t = app.add('task') t.job = sum t.args = [[1, 2], 0] t.description = 'test task' self.app.add(app) self.app.run() self.assertEqual(self.app.results[0], 3)
def test_single_runner_app_with_many_subtasks(self): self.assertEqual(self.app.queue, []) self.assertEqual(self.app.results, []) app = BuildApp() app.pool_size = 2 for _ in range(10): t = app.add('task') t.job = sum t.description = 'test task' t.args = [[1, 2], 0] self.app.add(app) self.app.run() self.assertEqual(len(self.app.results), 10) self.assertEqual(self.app.results[0], 3) self.assertEqual(sum(self.app.results), 30)