Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SlurmExecutorPlugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EOSC
SlurmExecutorPlugin
Commits
77e75f61
Commit
77e75f61
authored
5 years ago
by
Mattia Mancini
Browse files
Options
Downloads
Patches
Plain Diff
test for slurm_control list jobs command
parent
6aa152a1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
setup.py
+9
-0
9 additions, 0 deletions
setup.py
tests/test_slurm_cli.py
+49
-0
49 additions, 0 deletions
tests/test_slurm_cli.py
with
58 additions
and
0 deletions
setup.py
+
9
−
0
View file @
77e75f61
from
setuptools
import
setup
from
setuptools
import
setup
import
unittest
def
test_suite
():
test_loader
=
unittest
.
TestLoader
()
test_suite
=
test_loader
.
discover
(
'
tests
'
,
pattern
=
'
test_*.py
'
)
return
test_suite
setup
(
setup
(
name
=
"
slurm-executor-plugin
"
,
name
=
"
slurm-executor-plugin
"
,
...
@@ -7,6 +15,7 @@ setup(
...
@@ -7,6 +15,7 @@ setup(
url
=
'
https://git.astron.nl/eosc/slurmexecutorplugin/
'
,
url
=
'
https://git.astron.nl/eosc/slurmexecutorplugin/
'
,
package_dir
=
{
''
:
'
lib
'
},
package_dir
=
{
''
:
'
lib
'
},
packages
=
[
'
slurm_cli
'
,
'
slurm_executor
'
],
packages
=
[
'
slurm_cli
'
,
'
slurm_executor
'
],
test_suite
=
'
setup.test_suite
'
,
entry_points
=
{
entry_points
=
{
'
airflow.plugins
'
:
[
'
airflow.plugins
'
:
[
'
slurm = slurm_executor.slurm:SlurmExecutorPlugin
'
'
slurm = slurm_executor.slurm:SlurmExecutorPlugin
'
...
...
This diff is collapsed.
Click to expand it.
tests/test_slurm_cli.py
0 → 100644
+
49
−
0
View file @
77e75f61
import
slurm_cli.slurm_control
as
slurm_control
from
slurm_cli.jobs
import
SlurmJobStatus
import
unittest
from
unittest.mock
import
patch
,
MagicMock
from
subprocess
import
CompletedProcess
import
logging
def
get_mocked_call_output
(
status_code
,
stdout_string
,
stderr_string
):
mocked_run_return_value
=
MagicMock
(
CompletedProcess
)
mocked_run_return_value
.
stdout
=
stdout_string
mocked_run_return_value
.
stderr
=
stderr_string
mocked_run_return_value
.
returncode
=
status_code
return
mocked_run_return_value
class
TestSlurmControl
(
unittest
.
TestCase
):
@patch
(
'
slurm_cli.slurm_control.run_process
'
)
def
test_get_job_statuses_job_queue_empty
(
self
,
call_mock
):
output_string
=
''
call_mock
.
return_value
=
get_mocked_call_output
(
0
,
output_string
,
''
)
jobs
=
slurm_control
.
get_jobs_status
()
self
.
assertEqual
(
len
(
jobs
),
0
)
@patch
(
'
slurm_cli.slurm_control.run_process
'
)
def
test_get_job_statuses_job_queue_filled
(
self
,
call_mock
):
output_string
=
'
123;test_job;CD;COMPLETED;None
\n
124;test_job;F;FAILED;error 1
\n
'
expected_parsed_results
=
[
SlurmJobStatus
(
job_id
=
'
123
'
,
job_name
=
'
test_job
'
,
status_code
=
'
CD
'
,
status
=
'
COMPLETED
'
,
reason
=
'
None
'
),
SlurmJobStatus
(
job_id
=
'
124
'
,
job_name
=
'
test_job
'
,
status_code
=
'
F
'
,
status
=
'
FAILED
'
,
reason
=
'
error 1
'
)
]
call_mock
.
return_value
=
get_mocked_call_output
(
0
,
output_string
,
''
)
jobs
=
slurm_control
.
get_jobs_status
()
self
.
assertEqual
(
len
(
jobs
),
2
)
for
job_status
in
expected_parsed_results
:
self
.
assertIn
(
job_status
.
job_id
,
jobs
)
self
.
assertEqual
(
jobs
[
job_status
.
job_id
],
job_status
)
@patch
(
'
slurm_cli.slurm_control.run_process
'
)
def
test_get_job_statuses_command_non_zero_exit_code
(
self
,
call_mock
):
output_string
=
'
123;test_job;CD;COMPLETED;None
\n
124;test_job;F;FAILED;error 1
\n
'
call_mock
.
return_value
=
get_mocked_call_output
(
1
,
output_string
,
'
stuff
'
)
with
self
.
assertRaises
(
slurm_control
.
SlurmCallError
):
_
=
slurm_control
.
get_jobs_status
()
if
__name__
==
'
__main__
'
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
'
%(asctime)s-%(name)s-%(levelname)s %(message)s
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment