Skip to content

Commit

Permalink
Added tests for schema.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPaulBennett authored and MetRonnie committed Dec 5, 2023
1 parent 5816c53 commit 26c83e4
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions cylc/uiserver/tests/test_workflow_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import sqlite3

from cylc.flow.id import Tokens
from cylc.uiserver.schema import make_query
from cylc.uiserver.schema import make_task_query, make_jobs_query

'''This file tests the ability for the cylc UI to retrieve workflow information
and perform simple statistical calculations for the analysis tab'''


def test_make_query_1():
def test_make_task_query_1():
conn = sqlite3.connect(':memory:')
conn.execute('''CREATE TABLE task_jobs(cycle TEXT, name TEXT,
submit_num INTEGER, flow_nums TEXT, is_manual_submit INTEGER,
Expand All @@ -43,7 +43,7 @@ def test_make_query_1():
conn.commit()
workflow = Tokens('~user/workflow')

return_value = make_query(conn, workflow)
return_value = make_task_query(conn, workflow)

assert return_value[0]['count'] == 1
assert return_value[0]['cycle_point'] == '1'
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_make_query_1():
assert return_value[0]['total_quartiles'][2] == 600


def test_make_query_2():
def test_make_task_query_2():
conn = sqlite3.connect(':memory:')
conn.execute('''CREATE TABLE task_jobs(cycle TEXT, name TEXT,
submit_num INTEGER, flow_nums TEXT, is_manual_submit INTEGER,
Expand All @@ -103,7 +103,7 @@ def test_make_query_2():
conn.commit()
workflow = Tokens('~user/workflow')

return_value = make_query(conn, workflow)
return_value = make_task_query(conn, workflow)

assert return_value[0]['count'] == 2
assert return_value[0]['cycle_point'] == '2'
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_make_query_2():
assert return_value[0]['total_quartiles'][2] == 600


def test_make_query_3():
def test_make_task_query_3():
conn = sqlite3.connect(':memory:')
conn.execute('''CREATE TABLE task_jobs(cycle TEXT, name TEXT,
submit_num INTEGER, flow_nums TEXT, is_manual_submit INTEGER,
Expand Down Expand Up @@ -167,8 +167,9 @@ def test_make_query_3():
conn.commit()
workflow = Tokens('~user/workflow')

return_value = make_query(conn, workflow)
return_value = make_task_query(conn, workflow)

assert len(return_value) == 1
assert return_value[0]['count'] == 3
assert return_value[0]['cycle_point'] == '3'
assert return_value[0]['finished_time'] == '2022-12-16T15:12:00Z'
Expand Down Expand Up @@ -201,3 +202,59 @@ def test_make_query_3():
assert return_value[0]['queue_quartiles'][2] == 76
assert return_value[0]['run_quartiles'][2] == 644
assert return_value[0]['total_quartiles'][2] == 720


def test_make_jobs_query_1():
conn = sqlite3.connect(':memory:')
conn.execute('''CREATE TABLE task_jobs(cycle TEXT, name TEXT,
submit_num INTEGER, flow_nums TEXT, is_manual_submit INTEGER,
try_num INTEGER, time_submit TEXT, time_submit_exit TEXT,
submit_status INTEGER, time_run TEXT, time_run_exit TEXT,
run_signal TEXT, run_status INTEGER, platform_name TEXT,
job_runner_name TEXT, job_id TEXT,
PRIMARY KEY(cycle, name, submit_num));''')

conn.executemany(
'INSERT into task_jobs VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
[('1', 'Task_1', '01', '{1}', 0, 1,
'2022-12-14T15:00:00Z', '2022-12-14T15:01:00Z', 0,
'2022-12-14T15:01:00Z', '2022-12-14T15:10:00Z', None, 0,
'MyPlatform', 'User', 'UsersJob'),
('2', 'Task_1', '01', '{1}', 0, 1,
'2022-12-15T15:00:00Z', '2022-12-15T15:01:15Z', 0,
'2022-12-15T15:01:16Z', '2022-12-15T15:12:00Z', None, 0,
'MyPlatform', 'User', 'UsersJob'),
('3', 'Task_1', '01', '{1}', 0, 1,
'2022-12-16T15:00:00Z', '2022-12-16T15:01:15Z', 0,
'2022-12-16T15:01:16Z', '2022-12-16T15:12:00Z', None, 0,
'MyPlatform', 'User', 'UsersJob')
])
conn.commit()
workflow = Tokens('~user/workflow')
tasks = []

return_value = make_jobs_query(conn, workflow, tasks)

assert len(return_value) == 3

assert return_value[0]['cycle_point'] == '1'
assert return_value[0]['finished_time'] == '2022-12-14T15:10:00Z'
assert return_value[0]['id'].id == '~user/workflow//1/Task_1/01'
assert return_value[0]['job_ID'] == 'UsersJob'
assert return_value[0]['name'] == 'Task_1'
assert return_value[0]['platform'] == 'MyPlatform'
assert return_value[0]['started_time'] == '2022-12-14T15:01:00Z'
assert return_value[0]['state'] == 0
assert return_value[0]['submit_num'] == 1
assert return_value[0]['submitted_time'] == '2022-12-14T15:00:00Z'

assert return_value[1]['cycle_point'] == '2'
assert return_value[1]['finished_time'] == '2022-12-15T15:12:00Z'
assert return_value[1]['id'].id == '~user/workflow//2/Task_1/01'
assert return_value[1]['job_ID'] == 'UsersJob'
assert return_value[1]['name'] == 'Task_1'
assert return_value[1]['platform'] == 'MyPlatform'
assert return_value[1]['started_time'] == '2022-12-15T15:01:16Z'
assert return_value[1]['state'] == 0
assert return_value[1]['submit_num'] == 1
assert return_value[1]['submitted_time'] == '2022-12-15T15:00:00Z'

0 comments on commit 26c83e4

Please sign in to comment.