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
b51ff131
Commit
b51ff131
authored
1 year ago
by
Ashwin Kumar Karnad
Browse files
Options
Downloads
Patches
Plain Diff
update tests to use pytest temp_dir
parent
158bc904
No related branches found
Branches containing commit
No related tags found
2 merge requests
!19
Move linux-debian11 into main
,
!1
Resolve "First draft for user interface for top level install command"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests.py
+17
-33
17 additions, 33 deletions
tests.py
with
17 additions
and
33 deletions
tests.py
+
17
−
33
View file @
b51ff131
...
@@ -6,57 +6,48 @@ import time
...
@@ -6,57 +6,48 @@ import time
import
shutil
import
shutil
mod
=
importlib
.
import_module
(
"
install-mpsd-software-environment
"
)
mod
=
importlib
.
import_module
(
"
install-mpsd-software-environment
"
)
test_release_path
=
(
"
/tmp/test_prepare_env
"
# temporary directory for testing used by multiple tests
)
def
test_os_chdir
():
def
test_os_chdir
(
tmp_path
):
# create a temporary directory for testing
# create a temporary directory for testing
temp_dir
=
"
/
tmp
/
test_os_chdir
"
temp_dir
=
tmp
_path
/
"
test_os_chdir
"
os
.
mkdir
(
temp_dir
)
temp_dir
.
mkdir
(
)
# initial current working directory
# initial current working directory
initial_cwd
=
os
.
getcwd
()
initial_cwd
=
os
.
getcwd
()
# change to the temporary directory using os_chdir
# change to the temporary directory using os_chdir
with
mod
.
os_chdir
(
temp_dir
):
with
mod
.
os_chdir
(
str
(
temp_dir
)
)
:
assert
os
.
getcwd
()
==
os
.
path
.
abspath
(
temp_dir
)
assert
os
.
getcwd
()
==
str
(
temp_dir
)
# current working directory should be back to initial directory
# current working directory should be back to initial directory
assert
os
.
getcwd
()
==
initial_cwd
assert
os
.
getcwd
()
==
initial_cwd
# clean up the temporary directory
os
.
rmdir
(
temp_dir
)
def
test_prepare_env
():
def
test_prepare_env
(
tmp_path
):
# simulate running ./install-software-environment.py --release dev-23a --target-directory /tmp/test_prepare_env
# simulate running ./install-software-environment.py --release dev-23a --target-directory /tmp/test_prepare_env
# prepare_env is run when cmd is not specified, we can test cmd='prepare' and cmd=None to check both cases
# prepare_env is run when cmd is not specified, we can test cmd='prepare' and cmd=None to check both cases
# if the directory exists, remove it
if
os
.
path
.
exists
(
test_release_path
):
shutil
.
rmtree
(
test_release_path
)
# check that the test directory does not exist
# check that the test directory does not exist
assert
not
os
.
path
.
exists
(
test_re
lease_path
)
assert
not
(
tmp_path
/
"
test_
p
re
pare_env
"
).
exists
(
)
run
=
mod
.
builder
(
run
=
mod
.
builder
(
release
=
"
dev-23a
"
,
release
=
"
dev-23a
"
,
cmd
=
"
prepare
"
,
cmd
=
"
prepare
"
,
target_dir
=
test_re
lease_path
,
target_dir
=
str
(
tmp_path
/
"
test_
p
re
pare_env
"
)
,
skip_build_cache
=
False
,
skip_build_cache
=
False
,
)
)
run
.
run
()
run
.
run
()
# wait for 20 seconds for the git clone to finish
# wait for 20 seconds for the git clone to finish
# time.sleep(20)
# time.sleep(20)
# check if the directory now is created
# check if the directory now is created
assert
os
.
path
.
exists
(
test_re
lease_path
)
assert
(
tmp_path
/
"
test_
p
re
pare_env
"
).
exists
(
)
# check for spack-environments directory
# check for spack-environments directory
assert
os
.
listdir
(
test_re
lease_path
)
==
[
"
spack-environments
"
]
assert
os
.
listdir
(
str
(
tmp_path
/
"
test_
p
re
pare_env
"
)
)
==
[
"
spack-environments
"
]
# check if the git branch is correctl checked out
# check if the git branch is correctl checked out
assert
(
assert
(
subprocess
.
run
(
subprocess
.
run
(
"
cd
/tmp/
test_prepare_env/spack-environments && git branch
"
,
f
"
cd
{
str
(
tmp_path
/
'
test_prepare_env/spack-environments
'
)
}
&& git branch
"
,
shell
=
True
,
shell
=
True
,
capture_output
=
True
,
capture_output
=
True
,
)
)
...
@@ -69,25 +60,25 @@ def test_prepare_env():
...
@@ -69,25 +60,25 @@ def test_prepare_env():
run
=
mod
.
builder
(
run
=
mod
.
builder
(
release
=
"
dev-23a
"
,
release
=
"
dev-23a
"
,
cmd
=
None
,
cmd
=
None
,
target_dir
=
test_re
lease_path
,
target_dir
=
str
(
tmp_path
/
"
test_
p
re
pare_env
"
)
,
skip_build_cache
=
False
,
skip_build_cache
=
False
,
)
)
run
.
run
()
run
.
run
()
# check that ValueError is
not raised if skip_dir_check is True
# check that ValueError is not raised if skip_dir_check is True
run
=
mod
.
builder
(
run
=
mod
.
builder
(
release
=
"
dev-23a
"
,
release
=
"
dev-23a
"
,
cmd
=
None
,
cmd
=
None
,
target_dir
=
test_re
lease_path
,
target_dir
=
str
(
tmp_path
/
"
test_
p
re
pare_env
"
)
,
skip_build_cache
=
False
,
skip_build_cache
=
False
,
)
)
run
.
skip_dir_check
=
True
run
.
skip_dir_check
=
True
run
.
run
()
run
.
run
()
# clean up the temporary directory
# clean up the temporary directory
shutil
.
rmtree
(
test_re
lease_path
)
shutil
.
rmtree
(
str
(
tmp_path
/
"
test_
p
re
pare_env
"
)
)
def
test_setup_log_cmd
():
def
test_setup_log_cmd
(
tmp_path
):
# check that logs/install-software-environment.log is updated when the module is run
# check that logs/install-software-environment.log is updated when the module is run
log_file
=
"
logs/install-software-environment.log
"
log_file
=
"
logs/install-software-environment.log
"
if
os
.
path
.
exists
(
log_file
):
if
os
.
path
.
exists
(
log_file
):
...
@@ -96,14 +87,7 @@ def test_setup_log_cmd():
...
@@ -96,14 +87,7 @@ def test_setup_log_cmd():
initial_bytes
=
0
initial_bytes
=
0
# run the prepare_env functionality
# run the prepare_env functionality
run
=
mod
.
builder
(
mod
.
prepare_env
(
toolchain_base_dir
=
str
(
tmp_path
),
mpsd_spack_ver
=
'
dev-23a
'
,
skip_dir_check
=
False
,
shared_var
=
shared_var
)
release
=
"
dev-23a
"
,
cmd
=
None
,
target_dir
=
test_release_path
,
skip_build_cache
=
False
,
)
run
.
skip_dir_check
=
True
run
.
run
()
# check that logs/install-software-environment.log is updated
# check that logs/install-software-environment.log is updated
assert
os
.
path
.
exists
(
"
logs/install-software-environment.log
"
)
assert
os
.
path
.
exists
(
"
logs/install-software-environment.log
"
)
...
...
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