Skip to content

Commit 684ccbd

Browse files
committed
Add --trilinos-dir Check
Ensure --trilinos-dir points to the root of the Trilinos repository.
1 parent 220eddc commit 684ccbd

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

Diff for: scripts/snapshot_into_trilinos.py

+51-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
pytest snapshot_into_trilinos.py
1717
"""
1818
import os
19+
import pytest
1920
import sys
2021

2122

@@ -69,7 +70,7 @@ def parse_arguments(argv):
6970

7071
def test_parse_arguments():
7172
"""
72-
Test that the parse_arguments() function works as intended.
73+
Test that the :func:`parse_arguments` function works as intended.
7374
"""
7475
options = parse_arguments("--trilinos-dir /path/to/Trilinos --dry-run".
7576
split())
@@ -84,6 +85,51 @@ def test_parse_arguments():
8485

8586

8687

88+
def check_trilinos_dir_is_root(trilinos_dir):
89+
"""
90+
Check to ensure the Trilinos directory specified is indeed the root of the
91+
Trilinos repository by ensuring it contains a ``ProjectName.cmake`` that
92+
specifies Trilinos as the project name.
93+
"""
94+
import re
95+
try:
96+
with open(os.path.join(trilinos_dir, "ProjectName.cmake"), "r") as f:
97+
data = f.read().lower()
98+
if not re.search(r"set\s*\(\s*project_name\s+trilinos\s*\)", data):
99+
sys.exit(f"Error: {trilinos_dir}/ProjectName.cmake does not "
100+
"set the project name to Trilinos. Make sure you "
101+
"point to the root of the Trilinos repository.")
102+
except FileNotFoundError:
103+
sys.exit(f"Error: {trilinos_dir} does not contain a "
104+
"ProjectName.cmake. Make sure you point to the root of the "
105+
"Trilinos repository.")
106+
107+
108+
109+
def test_check_trilinos_dir_is_root(tmpdir):
110+
"""
111+
Test that the :func:`check_trilinos_dir_is_root` function works as
112+
intended.
113+
"""
114+
# Ensure the check fails if trilinos_dir doesn't contain ProjectName.cmake.
115+
trilinos_dir = tmpdir.mkdir("trilinos_dir")
116+
with pytest.raises(SystemExit):
117+
check_trilinos_dir_is_root(trilinos_dir)
118+
119+
# Ensure the check fails if ProjectName.cmake doesn't set the project name
120+
# to Trilinos.
121+
file_to_check = trilinos_dir.join("ProjectName.cmake")
122+
file_to_check.write("Doesn't set PROJECT_NAME to Trilinos")
123+
with pytest.raises(SystemExit):
124+
check_trilinos_dir_is_root(trilinos_dir)
125+
126+
# Ensure the check passes if ProjectName.cmake does set the project name to
127+
# Trilinos.
128+
file_to_check.write("SET(PROJECT_NAME Trilinos)")
129+
check_trilinos_dir_is_root(trilinos_dir)
130+
131+
132+
87133
def create_directory_variables(trilinos_dir, verbose=False):
88134
"""
89135
Use the given path to Trilinos to create a handful of other variables
@@ -117,7 +163,8 @@ def create_directory_variables(trilinos_dir, verbose=False):
117163

118164
def test_create_directory_variables(capfd):
119165
"""
120-
Test that the create_directory_variables() function works as intended.
166+
Test that the :func:`create_directory_variables` function works as
167+
intended.
121168
"""
122169
trilinos_dir = "/path/to/Trilinos"
123170
compadre_dir = os.path.abspath(os.path.join(os.path.dirname(
@@ -168,7 +215,7 @@ def create_snapshot_dir_args(orig_dir, dest_dir, dry_run=False):
168215

169216
def test_create_snapshot_dir_args():
170217
"""
171-
Test that the create_snapshot_dir_args() function works as intended.
218+
Test that the :func:`create_snapshot_dir_args` function works as intended.
172219
"""
173220
orig = "from_here"
174221
dest = "to_there"
@@ -206,6 +253,7 @@ def snapshot(snapshot_dir_args):
206253

207254
if __name__ == "__main__":
208255
options = parse_arguments(sys.argv[1:])
256+
check_trilinos_dir_is_root(options.trilinos_dir)
209257
(orig_dir, dest_dir) = create_directory_variables(options.trilinos_dir,
210258
options.dry_run)
211259
success = snapshot(create_snapshot_dir_args(orig_dir, dest_dir,

0 commit comments

Comments
 (0)