16
16
pytest snapshot_into_trilinos.py
17
17
"""
18
18
import os
19
+ import pytest
19
20
import sys
20
21
21
22
@@ -69,7 +70,7 @@ def parse_arguments(argv):
69
70
70
71
def test_parse_arguments ():
71
72
"""
72
- Test that the parse_arguments() function works as intended.
73
+ Test that the :func:` parse_arguments` function works as intended.
73
74
"""
74
75
options = parse_arguments ("--trilinos-dir /path/to/Trilinos --dry-run" .
75
76
split ())
@@ -84,6 +85,51 @@ def test_parse_arguments():
84
85
85
86
86
87
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
+
87
133
def create_directory_variables (trilinos_dir , verbose = False ):
88
134
"""
89
135
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):
117
163
118
164
def test_create_directory_variables (capfd ):
119
165
"""
120
- Test that the create_directory_variables() function works as intended.
166
+ Test that the :func:`create_directory_variables` function works as
167
+ intended.
121
168
"""
122
169
trilinos_dir = "/path/to/Trilinos"
123
170
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):
168
215
169
216
def test_create_snapshot_dir_args ():
170
217
"""
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.
172
219
"""
173
220
orig = "from_here"
174
221
dest = "to_there"
@@ -206,6 +253,7 @@ def snapshot(snapshot_dir_args):
206
253
207
254
if __name__ == "__main__" :
208
255
options = parse_arguments (sys .argv [1 :])
256
+ check_trilinos_dir_is_root (options .trilinos_dir )
209
257
(orig_dir , dest_dir ) = create_directory_variables (options .trilinos_dir ,
210
258
options .dry_run )
211
259
success = snapshot (create_snapshot_dir_args (orig_dir , dest_dir ,
0 commit comments