You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/libs/wraptor/context/test/test_maybe.py

27 lines
596 B

from threading import Thread
from wraptor.context import maybe
def test_basic():
with maybe(lambda: False):
assert False
check = False
with maybe(lambda: True):
check = True
assert check
def test_threads():
def worker(arr, index):
for i in range(5):
with maybe(lambda: i == 3):
arr[index] = True
workers = 100
arr = [False for i in range(workers)]
threads = [Thread(target=worker, args=(arr, i)) for i in range(workers)]
[t.start() for t in threads]
[t.join() for t in threads]
assert all(arr)