def test_results_order(self): def func(x): time.sleep(x) return x values = tuple(random.random() * 0.1 for x in range(10)) results = concurrent.tmap(func, values) expected = [concurrent.Result(True, x) for x in values] self.assertEqual(results, expected)
def test_error(self): error = RuntimeError("No result for you!") def func(x): raise error results = concurrent.tmap(func, range(10)) expected = [concurrent.Result(False, error)] * 10 self.assertEqual(results, expected)
def test_concurrency(self): start = time.time() concurrent.tmap(time.sleep, [0.5] * 10) elapsed = time.time() - start self.assertGreater(elapsed, 0.5) self.assertLess(elapsed, 1.0)
def test_results(self): values = tuple(range(10)) results = concurrent.tmap(lambda x: x, values) expected = [concurrent.Result(True, x) for x in values] self.assertEqual(results, expected)
def test_concurrency(self): start = time.time() concurrent.tmap(time.sleep, [0.1] * 10) elapsed = time.time() - start self.assertTrue(0.1 < elapsed < 0.2)