Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpsd-software-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
MPSD Computational Science
mpsd-software-manager
Commits
7a92de7c
Commit
7a92de7c
authored
1 year ago
by
Hans Fangohr
Browse files
Options
Downloads
Plain Diff
Merge branch 'run-tests-for-run' into linux-debian11
parents
34c81bb1
078ddffc
No related branches found
No related tags found
2 merge requests
!19
Move linux-debian11 into main
,
!14
Draft: Add tests for run method
Pipeline
#368642
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests.py
+35
-0
35 additions, 0 deletions
tests.py
with
35 additions
and
0 deletions
tests.py
+
35
−
0
View file @
7a92de7c
...
...
@@ -63,6 +63,41 @@ def test_os_chdir(tmp_path):
assert
os
.
getcwd
()
==
initial_cwd
def
test_run_method
(
tmp_path
):
"""
Run tests for run method.
"""
run
=
mod
.
run
# test a command with options:
assert
run
([
"
date
"
,
"
+%Y-%m-%d
"
]).
returncode
==
0
assert
run
(
"
date +%Y-%m-%d
"
,
shell
=
True
).
returncode
==
0
# tests interacting with the file system
with
mod
.
os_chdir
(
str
(
tmp_path
)):
# ensure single string command works
assert
run
((
"
ls -l
"
),
shell
=
True
).
returncode
==
0
# test spaces are handled correctly:
assert
run
([
"
touch
"
,
"
file1
"
,
"
file2
"
]).
returncode
==
0
assert
os
.
path
.
exists
(
"
file1
"
)
assert
os
.
path
.
exists
(
"
file2
"
)
# test output is captured:
assert
(
b
"
Hello, world!
\n
"
in
run
([
"
echo
"
,
"
Hello, world!
"
],
capture_output
=
True
).
stdout
)
# check exceptions
with
pytest
.
raises
(
FileNotFoundError
):
run
([
"
doesnotexistcommand
"
])
# check error code is checked
# 1. expect this to parse: return code is non-zero, but we don't check
run
([
"
ls
"
,
"
/doesnotexist
"
]),
# 2. expect this to fail:
with
pytest
.
raises
(
subprocess
.
CalledProcessError
):
run
([
"
ls
"
,
"
/doesnotexist
"
],
check
=
True
)
def
test_prepare_environment
(
tmp_path
):
"""
Simulate running preparation of environment.
...
...
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