Skip to content

Commit

Permalink
tests: polish
Browse files Browse the repository at this point in the history
  • Loading branch information
ebonnal committed Oct 18, 2024
1 parent 4fb1392 commit 8bf7be7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Lib/test/test_concurrent_futures/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,35 @@ def test_map_with_buffersize(self):
with self.assertRaisesRegex(ValueError, "buffersize must be None or >= 1."):
self.executor.map(bool, [], buffersize=0)

it = range(4)
iterable = range(4)
self.assertEqual(
list(self.executor.map(str, it, buffersize=1)),
list(map(str, it)),
list(self.executor.map(str, iterable, buffersize=1)),
list(map(str, iterable)),
)

def test_map_with_buffersize_and_timeout(self):
it = self.executor.map(time.sleep, (0, 1), timeout=0.5)
next(it)
results = self.executor.map(time.sleep, (0, 1), timeout=0.5)
next(results)
with self.assertRaises(TimeoutError):
next(it)
next(results)

def test_map_with_buffersize_on_infinite_iterable(self):
results = self.executor.map(str, itertools.count(1), buffersize=1)
self.assertEqual(next(iter(results)), "1")

def test_map_with_buffersize_on_iterable_smaller_than_buffer(self):
it = range(2)
results = self.executor.map(str, it, buffersize=10)
self.assertListEqual(list(results), list(map(str, it)))
iterable = range(2)
results = self.executor.map(str, iterable, buffersize=8)
self.assertListEqual(list(results), list(map(str, iterable)))

def test_map_with_buffersize_on_empty_iterable(self):
it = iter([])
results = self.executor.map(str, it, buffersize=10)
results = self.executor.map(str, [], buffersize=8)
self.assertListEqual(list(results), [])

def test_map_with_buffersize_when_buffer_becomes_full(self):
manager = multiprocessing.Manager()
iterable = range(8)
buffersize = 4
buffered_results = manager.list()
buffered_results = multiprocessing.Manager().list()
self.executor.map(buffered_results.append, iterable, buffersize=buffersize)
self.executor.shutdown(wait=True)
self.assertSetEqual(
Expand Down

0 comments on commit 8bf7be7

Please sign in to comment.