Skip to content

Commit e52a355

Browse files
authored
Merge pull request #338 from ExaWorks/330-automatic-test-of-some-documentation-code
330 automatic test of some documentation code
2 parents b343147 + e0ec118 commit e52a355

File tree

8 files changed

+111
-64
lines changed

8 files changed

+111
-64
lines changed

docs/_static/extras.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,28 @@ function detectAll(selectorType) {
5959
// Similarly, if "D" is selected in the second selector, we only want to change
6060
// simple_value_2. However, if either "B" or "C" are selected in either selector,
6161
// we want to change both.
62-
62+
63+
console.log("type:" + selectorType);
6364
$("p." + selectorType + "-selector").addClass(selectorType + "-item");
65+
var prevSpans = [];
6466
$("span").each(function() {
65-
if ($(this).text() == '"<&' + selectorType + '>"') {
67+
var text = $(this).text();
68+
// look for both "<&<type>>" and execparams.<type> to align with test cases
69+
70+
if (text == '"<&' + selectorType + '>"') {
6671
$(this).addClass(selectorType + "-item").addClass("psij-selector-value");
6772
}
73+
if (text == "executor" && prevSpans.length == 2
74+
&& prevSpans[0].text() == "execparams" && prevSpans[1].text() == '.') {
75+
// remove <span>execparams</span> and <span>.</span>
76+
prevSpans[0].remove();
77+
prevSpans[1].remove();
78+
$(this).addClass(selectorType + "-item").addClass("psij-selector-value");
79+
}
80+
prevSpans.push($(this));
81+
if (prevSpans.length > 2) {
82+
prevSpans.shift();
83+
}
6884
});
6985
}
7086

docs/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Local // Slurm // LSF // PBS // Cobalt
7979
8080
from psij import Job, JobExecutor, JobSpec
8181
82-
ex = JobExecutor.get_instance("<&executor-type>")
82+
ex = JobExecutor.get_instance(execparams.executor)
8383
job = Job(JobSpec(executable="/bin/date"))
8484
ex.submit(job)
8585

docs/user_guide.rst

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,10 @@ On a Slurm cluster, this code might look like:
100100

101101
Slurm // Local // LSF // PBS // Cobalt
102102

103-
.. code-block:: python
104-
105-
from psij import Job, JobExecutor, JobSpec
106-
107-
ex = JobExecutor.get_instance("<&executor-type>")
108-
job = Job(JobSpec(executable='/bin/date'))
109-
ex.submit(job)
103+
.. literalinclude:: ../tests/getting_started/test_single_job.py
104+
:language: python
105+
:dedent: 4
106+
:lines: 6-8
110107

111108
And by way of comparison, other backends can be selected with the tabs above.
112109
Note that the only difference is the argument to the ``get_instance`` method.
@@ -129,14 +126,10 @@ simple as adding a loop:
129126

130127
Slurm // Local // LSF // PBS // Cobalt
131128

132-
.. code-block:: python
133-
134-
from psij import Job, JobExecutor, JobSpec
135-
136-
ex = JobExecutor.get_instance("<&executor-type>")
137-
for _ in range(10):
138-
job = Job(JobSpec(executable="/bin/date"))
139-
ex.submit(job)
129+
.. literalinclude:: ../tests/getting_started/test_multiple_jobs.py
130+
:language: python
131+
:dedent: 4
132+
:lines: 6-9
140133

141134
Every :class:`JobExecutor <psij.job_executor.JobExecutor>` can handle arbitrary
142135
numbers of jobs (tested with up to 64k jobs).
@@ -171,13 +164,10 @@ formatting:
171164

172165
Slurm // Local // LSF // PBS // Cobalt
173166

174-
.. code-block:: python
175-
176-
from psij import Job, JobExecutor, JobSpec
177-
178-
ex = JobExecutor.get_instance('<&executor-type>')
179-
job = Job(JobSpec(executable='/bin/date', arguments=['-utc', '--debug']))
180-
ex.submit(job)
167+
.. literalinclude:: ../tests/getting_started/test_job_arguements.py
168+
:language: python
169+
:dedent: 4
170+
:lines: 6-8
181171

182172
Note: `JobSpec` attributes can also be added incrementally:
183173

@@ -305,23 +295,10 @@ attributes=my_job_attributes)``:
305295

306296
Slurm // Local // LSF // PBS // Cobalt
307297

308-
.. code-block:: python
309-
310-
from psij import Job, JobExecutor, JobSpec, JobAttributes, ResourceSpecV1
311-
312-
executor = JobExecutor.get_instance("<&executor-type>")
313-
314-
job = Job(
315-
JobSpec(
316-
executable="/bin/date",
317-
resources=ResourceSpecV1(node_count=1),
318-
attributes=JobAttributes(
319-
queue_name="<QUEUE_NAME>", project_name="<ALLOCATION>"
320-
),
321-
)
322-
)
323-
324-
executor.submit(job)
298+
.. literalinclude:: ../tests/getting_started/test_scheduling_information.py
299+
:language: python
300+
:dedent: 4
301+
:lines: 7-20
325302

326303
The `<QUEUE_NAME>` and `<ALLOCATION>` fields will depend on the system you are
327304
running on.
@@ -392,29 +369,14 @@ To wait on multiple jobs at once:
392369

393370
Slurm // Local // LSF // PBS // Cobalt
394371

395-
.. code-block:: python
396-
397-
import time
398-
from psij import Job, JobExecutor, JobSpec
399-
400-
count = 10
401-
402-
def callback(job, status):
403-
global count
404-
405-
if status.final:
406-
print(f"Job {job} completed with status {status}")
407-
count -= 1
408-
409-
ex = JobExecutor.get_instance("<&executor-type>")
410-
ex.set_job_status_callback(callback)
411-
412-
for _ in range(count):
413-
job = Job(JobSpec(executable="/bin/date"))
414-
ex.submit(job)
372+
.. literalinclude:: ../tests/getting_started/test_status_callbacks.py
373+
:language: python
374+
:lines: 5
415375

416-
while count > 0:
417-
time.sleep(0.01)
376+
.. literalinclude:: ../tests/getting_started/test_status_callbacks.py
377+
:language: python
378+
:dedent: 4
379+
:lines: 9-24
418380

419381
Status callbacks can also be set on individual jobs with
420382
:meth:`set_job_status_callback <psij.job.Job.set_job_status_callback>`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from psij import Job, JobSpec, JobExecutor
2+
from executor_test_params import ExecutorTestParams
3+
4+
5+
def test_getting_started_job_arguements(execparams: ExecutorTestParams) -> None:
6+
ex = JobExecutor.get_instance(execparams.executor)
7+
job = Job(JobSpec(executable='/bin/date', arguments=['-utc', '--debug']))
8+
ex.submit(job)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from psij import Job, JobSpec, JobExecutor
2+
from executor_test_params import ExecutorTestParams
3+
4+
5+
def test_getting_started_multiple_jobs(execparams: ExecutorTestParams) -> None:
6+
ex = JobExecutor.get_instance(execparams.executor)
7+
for _ in range(10):
8+
job = Job(JobSpec(executable="/bin/date"))
9+
ex.submit(job)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from psij import Job, JobSpec, JobExecutor, ResourceSpecV1
2+
# from psij import JobAttributes
3+
from executor_test_params import ExecutorTestParams
4+
5+
6+
def test_getting_started_scheduling_info(execparams: ExecutorTestParams) -> None:
7+
executor = JobExecutor.get_instance(execparams.executor)
8+
9+
job = Job(
10+
JobSpec(
11+
executable="/bin/date",
12+
resources=ResourceSpecV1(node_count=1),
13+
# attributes=JobAttributes(
14+
# queue_name="<QUEUE_NAME>",
15+
# project_name="<ALLOCATION>"
16+
# ),
17+
)
18+
)
19+
20+
executor.submit(job)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from psij import Job, JobSpec, JobExecutor
2+
from executor_test_params import ExecutorTestParams
3+
4+
5+
def test_getting_started_single_job(execparams: ExecutorTestParams) -> None:
6+
ex = JobExecutor.get_instance(execparams.executor)
7+
job = Job(JobSpec(executable='/bin/date', arguments=['-utc', '--debug']))
8+
ex.submit(job)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time
2+
from psij import Job, JobSpec, JobStatus, JobExecutor
3+
from executor_test_params import ExecutorTestParams
4+
5+
count = 10
6+
7+
8+
def test_getting_started_scheduling_info(execparams: ExecutorTestParams) -> None:
9+
def callback(job: Job, status: JobStatus) -> None:
10+
global count
11+
12+
if status.final:
13+
print(f"Job {job} completed with status {status}")
14+
count -= 1
15+
16+
ex = JobExecutor.get_instance(execparams.executor)
17+
ex.set_job_status_callback(callback)
18+
19+
for _ in range(count):
20+
job = Job(JobSpec(executable="/bin/date"))
21+
ex.submit(job)
22+
23+
while count > 0:
24+
time.sleep(0.01)

0 commit comments

Comments
 (0)