Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
eic_tools
Spack
Commits
5deaaa27
Commit
5deaaa27
authored
9 years ago
by
Massimiliano Culpo
Browse files
Options
Downloads
Patches
Plain Diff
modules : added a few unit tests
parent
bce276d5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/spack/spack/modules.py
+2
-4
2 additions, 4 deletions
lib/spack/spack/modules.py
lib/spack/spack/test/__init__.py
+1
-0
1 addition, 0 deletions
lib/spack/spack/test/__init__.py
lib/spack/spack/test/modules.py
+126
-0
126 additions, 0 deletions
lib/spack/spack/test/modules.py
with
129 additions
and
4 deletions
lib/spack/spack/modules.py
+
2
−
4
View file @
5deaaa27
...
@@ -132,17 +132,15 @@ def dependencies(spec, request='all'):
...
@@ -132,17 +132,15 @@ def dependencies(spec, request='all'):
if
request
==
'
none
'
:
if
request
==
'
none
'
:
return
[]
return
[]
l
=
[
xx
for
xx
in
sorted
(
spec
.
traverse
(
order
=
'
post
'
,
depth
=
True
,
cover
=
'
nodes
'
,
root
=
False
),
reverse
=
True
)]
if
request
==
'
direct
'
:
if
request
==
'
direct
'
:
return
[
xx
for
ii
,
xx
in
l
if
ii
==
1
]
return
[
xx
for
_
,
xx
in
spec
.
dependencies
.
items
()
]
# FIXME : during module file creation nodes seem to be visited multiple times even if cover='nodes'
# FIXME : during module file creation nodes seem to be visited multiple times even if cover='nodes'
# FIXME : is given. This work around permits to get a unique list of spec anyhow.
# FIXME : is given. This work around permits to get a unique list of spec anyhow.
# FIXME : Possibly we miss a merge step among nodes that refer to the same package.
# FIXME : Possibly we miss a merge step among nodes that refer to the same package.
seen
=
set
()
seen
=
set
()
seen_add
=
seen
.
add
seen_add
=
seen
.
add
l
=
[
xx
for
xx
in
sorted
(
spec
.
traverse
(
order
=
'
post
'
,
depth
=
True
,
cover
=
'
nodes
'
,
root
=
False
),
reverse
=
True
)]
return
[
xx
for
ii
,
xx
in
l
if
not
(
xx
in
seen
or
seen_add
(
xx
))]
return
[
xx
for
ii
,
xx
in
l
if
not
(
xx
in
seen
or
seen_add
(
xx
))]
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/test/__init__.py
+
1
−
0
View file @
5deaaa27
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
'
svn_fetch
'
,
'
svn_fetch
'
,
'
hg_fetch
'
,
'
hg_fetch
'
,
'
mirror
'
,
'
mirror
'
,
'
modules
'
,
'
url_extrapolate
'
,
'
url_extrapolate
'
,
'
cc
'
,
'
cc
'
,
'
link_tree
'
,
'
link_tree
'
,
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/test/modules.py
0 → 100644
+
126
−
0
View file @
5deaaa27
import
collections
from
contextlib
import
contextmanager
import
StringIO
FILE_REGISTRY
=
collections
.
defaultdict
(
StringIO
.
StringIO
)
# Monkey-patch open to write module files to a StringIO instance
@contextmanager
def
mock_open
(
filename
,
mode
):
if
not
mode
==
'
w
'
:
raise
RuntimeError
(
'
test.modules : unexpected opening mode for monkey-patched open
'
)
FILE_REGISTRY
[
filename
]
=
StringIO
.
StringIO
()
try
:
yield
FILE_REGISTRY
[
filename
]
finally
:
handle
=
FILE_REGISTRY
[
filename
]
FILE_REGISTRY
[
filename
]
=
handle
.
getvalue
()
handle
.
close
()
import
spack.modules
configuration_autoload_direct
=
{
'
enable
'
:
[
'
tcl
'
],
'
tcl
'
:
{
'
all
'
:
{
'
autoload
'
:
'
direct
'
}
}
}
configuration_autoload_all
=
{
'
enable
'
:
[
'
tcl
'
],
'
tcl
'
:
{
'
all
'
:
{
'
autoload
'
:
'
all
'
}
}
}
configuration_alter_environment
=
{
'
enable
'
:
[
'
tcl
'
],
'
tcl
'
:
{
'
all
'
:
{
'
filter
'
:
{
'
environment_blacklist
'
:
[
'
CMAKE_PREFIX_PATH
'
]}
},
'
=x86-linux
'
:
{
'
environment
'
:
{
'
set
'
:
[
'
FOO,foo
'
],
'
unset
'
:
[
'
BAR
'
]}
}
}
}
configuration_blacklist
=
{
'
enable
'
:
[
'
tcl
'
],
'
tcl
'
:
{
'
blacklist
'
:
[
'
callpath
'
],
'
all
'
:
{
'
autoload
'
:
'
direct
'
}
}
}
from
spack.test.mock_packages_test
import
MockPackagesTest
class
TclTests
(
MockPackagesTest
):
def
setUp
(
self
):
super
(
TclTests
,
self
).
setUp
()
self
.
configuration_obj
=
spack
.
modules
.
CONFIGURATION
spack
.
modules
.
open
=
mock_open
spack
.
modules
.
CONFIGURATION
=
None
# Make sure that a non-mocked configuration will trigger an error
def
tearDown
(
self
):
del
spack
.
modules
.
open
spack
.
modules
.
CONFIGURATION
=
self
.
configuration_obj
super
(
TclTests
,
self
).
tearDown
()
def
get_modulefile_content
(
self
,
spec
):
spec
.
concretize
()
generator
=
spack
.
modules
.
TclModule
(
spec
)
generator
.
write
()
content
=
FILE_REGISTRY
[
generator
.
file_name
].
split
(
'
\n
'
)
return
content
def
test_simple_case
(
self
):
spack
.
modules
.
CONFIGURATION
=
configuration_autoload_direct
spec
=
spack
.
spec
.
Spec
(
'
mpich@3.0.4=x86-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertTrue
(
'
module-whatis
"
mpich @3.0.4
"'
in
content
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
x
.
startswith
(
'
prepend-path CMAKE_PREFIX_PATH
'
)]),
1
)
def
test_autoload
(
self
):
spack
.
modules
.
CONFIGURATION
=
configuration_autoload_direct
spec
=
spack
.
spec
.
Spec
(
'
mpileaks=x86-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
is-loaded
'
in
x
]),
2
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
module load
'
in
x
]),
2
)
spack
.
modules
.
CONFIGURATION
=
configuration_autoload_all
spec
=
spack
.
spec
.
Spec
(
'
mpileaks=x86-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
is-loaded
'
in
x
]),
5
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
module load
'
in
x
]),
5
)
def
test_alter_environment
(
self
):
spack
.
modules
.
CONFIGURATION
=
configuration_alter_environment
spec
=
spack
.
spec
.
Spec
(
'
mpileaks=x86-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
x
.
startswith
(
'
prepend-path CMAKE_PREFIX_PATH
'
)]),
0
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
setenv FOO
"
foo
"'
in
x
]),
1
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
unsetenv BAR
'
in
x
]),
1
)
spec
=
spack
.
spec
.
Spec
(
'
libdwarf=x64-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
x
.
startswith
(
'
prepend-path CMAKE_PREFIX_PATH
'
)]),
0
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
setenv FOO
"
foo
"'
in
x
]),
0
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
unsetenv BAR
'
in
x
]),
0
)
def
test_blacklist
(
self
):
spack
.
modules
.
CONFIGURATION
=
configuration_blacklist
spec
=
spack
.
spec
.
Spec
(
'
mpileaks=x86-linux
'
)
content
=
self
.
get_modulefile_content
(
spec
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
is-loaded
'
in
x
]),
1
)
self
.
assertEqual
(
len
([
x
for
x
in
content
if
'
module load
'
in
x
]),
1
)
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