Skip to content

Commit 7bfcbfa

Browse files
RamonAra209hategan
authored andcommitted
tests: added tests for getting-started section of online docs
* tests: added llnl specific tests from getting-started documentation * tests: divided llnl doc tests into subfolder within tests * linting: applied type annotations * tests: Added doc tests with executor parameters * deleted: old folder of slurm/lsf specific tests * getting started doc tests: fixed status callback test * addressing linting * addressing linting
1 parent b747107 commit 7bfcbfa

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/test_getting_started_docs.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Functions for testing the various code snippets available in psij docs - 'getting started'."""
2+
from time import sleep
3+
from psij import Job, JobSpec, JobStatus
4+
from executor_test_params import ExecutorTestParams
5+
from _test_tools import _get_executor_instance, _get_timeout, assert_completed
6+
7+
status_callback_job_count = 3
8+
9+
10+
def test_getting_started_basic_usage(execparams: ExecutorTestParams) -> None:
11+
job = Job(
12+
JobSpec(
13+
executable="/bin/date",
14+
launcher=execparams.launcher
15+
)
16+
)
17+
ex = _get_executor_instance(execparams, job)
18+
ex.submit(job)
19+
status = job.wait(timeout=_get_timeout(execparams))
20+
assert_completed(job, status)
21+
22+
23+
def test_getting_started_adding_complexity(execparams: ExecutorTestParams) -> None:
24+
num_jobs = 3
25+
for _ in range(num_jobs):
26+
job = Job(
27+
JobSpec(
28+
executable="/bin/date",
29+
launcher=execparams.launcher
30+
)
31+
)
32+
ex = _get_executor_instance(execparams, job)
33+
ex.submit(job)
34+
35+
36+
def test_getting_started_status_callbacks(execparams: ExecutorTestParams) -> None:
37+
def callback(job: Job, status: JobStatus) -> None:
38+
global status_callback_job_count
39+
if status.final:
40+
print(f"Job {job} completed with status {status}")
41+
status_callback_job_count -= 1
42+
43+
for _ in range(status_callback_job_count):
44+
job = Job(JobSpec(executable='/bin/date', launcher=execparams.launcher))
45+
ex = _get_executor_instance(execparams, job)
46+
ex.set_job_status_callback(callback)
47+
ex.submit(job)
48+
49+
while status_callback_job_count > 0:
50+
sleep(0.01)
51+
52+
53+
def test_our_test(execparams: ExecutorTestParams) -> None:
54+
num_jobs = 3
55+
56+
def make_job() -> Job:
57+
job = Job()
58+
spec = JobSpec()
59+
spec.executable = 'echo'
60+
spec.arguments = ['HELLO WORLD!']
61+
job.spec = spec
62+
return job
63+
64+
jobs = []
65+
for _ in range(num_jobs):
66+
job: Job = make_job()
67+
jobs.append(job)
68+
jex = _get_executor_instance(execparams, job)
69+
jex.submit(job)
70+
71+
for job in jobs:
72+
job.wait()

0 commit comments

Comments
 (0)