Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Sep 9, 2020
1 parent ccc07ab commit d7ea902
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
4 changes: 2 additions & 2 deletions tests/test_default_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def task_func():
response = c.delete(f"/actions/{task_id}")
assert response.status_code == 200
# Test task was stopped
assert task_obj._status == "stopped"
assert task_obj._status == "cancelled"


def test_action_terminate(thing_client):
Expand All @@ -85,7 +85,7 @@ def task_func():
response = c.delete(f"/actions/{task_id}", json={"timeout": "0"})
assert response.status_code == 200
# Test task was stopped
assert task_obj._status == "terminated"
assert task_obj._status == "cancelled"


def test_action_kill_missing(thing_client):
Expand Down
32 changes: 4 additions & 28 deletions tests/test_tasks_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def task_func():
task_obj.start()
task_obj.join()
assert task_obj._return_value == "Return value"
assert task_obj._status == "success"
assert task_obj._status == "completed"


def test_task_get():
Expand Down Expand Up @@ -140,7 +140,7 @@ def task_func():
assert task_obj._status == "running"
task_obj.stop()
task_obj.join()
assert task_obj._status == "stopped"
assert task_obj._status == "cancelled"
assert task_obj._return_value is None


Expand All @@ -155,7 +155,7 @@ def task_func():
assert task_obj._status == "running"
task_obj.stop(timeout=0)
task_obj.join()
assert task_obj._status == "terminated"
assert task_obj._status == "cancelled"
assert task_obj._return_value is None


Expand All @@ -170,7 +170,7 @@ def task_func():
assert task_obj._status == "running"
task_obj.terminate()
task_obj.join()
assert task_obj._status == "terminated"
assert task_obj._status == "cancelled"
assert task_obj._return_value is None


Expand All @@ -184,30 +184,6 @@ def task_func():
assert task_obj.terminate() is False


def test_task_log_list():
import logging
import os

logging.getLogger().setLevel("INFO")

def task_func():
logging.warning("Task warning")
for i in range(10):
logging.info(f"Counted to {i}")

task_obj = thread.ActionThread(target=task_func)
task_obj.start()
task_obj.started.wait()

task_obj.join()
assert task_obj.log[0]["message"] == "Task warning"
assert task_obj.log[0]["levelname"] == "WARNING"
assert task_obj.log[0]["filename"] == os.path.basename(__file__)
assert (
len(task_obj.log) == 11
), "Didn't get the right number of log entries - are INFO entries being logged?"


def test_task_log_without_thread():

task_log_handler = thread.ThreadLogHandler()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def post(self):
action_thread = Index._deque[0]
assert action_thread.default_stop_timeout == 0
action_thread.stop()
assert action_thread.status == "terminated"
assert action_thread.status == "cancelled"

0 comments on commit d7ea902

Please sign in to comment.