Skip to content

Commit

Permalink
Fix tests to use with correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
timgates42 committed May 18, 2021
1 parent 6db708f commit 62a5971
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
33 changes: 18 additions & 15 deletions app/tests/test_controller.py
Expand Up @@ -22,8 +22,9 @@ def test_add():
handlers=handlers, input_queue=input_queue, threadpool=threadpool
)
task = {"interactive": True, "priority": 1}
# Exercise
controller.add(task)
with controller:
# Exercise
controller.add(task)
# Verify
assert input_queue.pop() == task # noqa=S101 # nosec

Expand Down Expand Up @@ -51,14 +52,15 @@ def gen_handle(_):
task = {"interactive": True, "priority": 1}
runtask = {"interactive": False, "name": "1"}
pendingtask = {"interactive": False, "name": "1"}
controller.add(task)
controller.add(runtask)
controller.add(pendingtask)
threadpool.drain()
with cond:
cond.notify()
# Exercise
result = controller.save()
with controller:
controller.add(task)
controller.add(runtask)
controller.add(pendingtask)
threadpool.drain()
with cond:
cond.notify()
# Exercise
result = controller.save()
# Verify
assert result == [task, pendingtask] # noqa=S101 # nosec

Expand All @@ -83,10 +85,11 @@ def handle():
)
task = {"interactive": True, "priority": 1, "name": "1"}
nexttask = {"interactive": True, "priority": 2, "name": "1"}
controller.add(task)
controller.add(nexttask)
interaction = KeyboardInteraction()
# Exercise
result = controller.run(interaction)
with controller:
controller.add(task)
controller.add(nexttask)
interaction = KeyboardInteraction()
# Exercise
result = controller.run(interaction)
# Verify
assert result == [nexttask] # noqa=S101 # nosec
36 changes: 19 additions & 17 deletions app/tests/test_threadpool.py
Expand Up @@ -23,10 +23,11 @@ def load_run(_):
return run

pool = get_pool({"run": load_run})
# Exercise
pool.add({"name": "run"}, None)
# Verify
pool.stop()
with pool:
# Exercise
pool.add({"name": "run"}, None)
# Verify
pool.stop()
assert result[0] # noqa=S101 # nosec


Expand All @@ -47,18 +48,19 @@ def load_run(_):
return run

pool = get_pool({"run": load_run}, max_workers=2)
taskjson = {"name": "run"}
for _ in range(10):
pool.add(taskjson, None)
with cond:
while running[0] < 2:
cond.wait()
pool.drain()
with cond:
cond.notify()
cond.notify()
pool.stop()
# Exercise
result = pool.save()
with pool:
taskjson = {"name": "run"}
for _ in range(10):
pool.add(taskjson, None)
with cond:
while running[0] < 2:
cond.wait()
pool.drain()
with cond:
cond.notify()
cond.notify()
pool.stop()
# Exercise
result = pool.save()
# Verify
assert result == ([taskjson] * 8) # noqa=S101 # nosec

0 comments on commit 62a5971

Please sign in to comment.