@@ -65,96 +65,131 @@ def test_clib_names():
65
65
clib_names ("meh" )
66
66
67
67
68
- def test_clib_full_names (monkeypatch ):
68
+ @pytest .fixture (scope = "module" , name = "os_name" )
69
+ def fixture_os_name ():
69
70
"""
70
- Make sure that clib_full_names() returns a generator with expected length
71
- for different cases.
71
+ Return the name of the current operating system.
72
72
"""
73
- os_name = sys .platform
73
+ return sys .platform
74
74
75
- # 1. GMT_LIBRARY_PATH and PATH are undefined
75
+
76
+ @pytest .fixture (scope = "module" , name = "gmt_lib_names" )
77
+ def fixture_gmt_lib_names (os_name ):
78
+ """
79
+ Return a list of the library names for the current operating system.
80
+ """
81
+ return clib_names (os_name )
82
+
83
+
84
+ @pytest .fixture (scope = "module" , name = "gmt_bin_realpath" )
85
+ def fixture_gmt_bin_realpath ():
86
+ """
87
+ Return the real path of GMT's "gmt" command.
88
+ """
89
+ return shutil .which ("gmt" )
90
+
91
+
92
+ @pytest .fixture (scope = "module" , name = "gmt_lib_realpath" )
93
+ def fixture_gmt_lib_realpath ():
94
+ """
95
+ Return the real path of the GMT library.
96
+ """
97
+ return subprocess .check_output (["gmt" , "--show-library" ], encoding = "utf-8" ).rstrip (
98
+ "\n "
99
+ )
100
+
101
+
102
+ def test_clib_full_names_gmt_library_path_undefined_path_empty (
103
+ monkeypatch , gmt_lib_names
104
+ ):
105
+ """
106
+ Make sure that clib_full_names() returns a generator with expected names
107
+ when GMT_LIBRARY_PATH is undefined and PATH is empty.
108
+ """
76
109
with monkeypatch .context () as mpatch :
77
110
mpatch .delenv ("GMT_LIBRARY_PATH" , raising = False )
78
111
mpatch .setenv ("PATH" , "" )
79
112
80
113
lib_fullpaths = clib_full_names ()
81
114
assert isinstance (lib_fullpaths , types .GeneratorType )
115
+ assert list (lib_fullpaths ) == gmt_lib_names
82
116
83
- lib_fullpaths = list (lib_fullpaths )
84
- if os_name .startswith ("linux" ):
85
- assert lib_fullpaths == ["libgmt.so" ]
86
- elif os_name == "darwin" :
87
- assert lib_fullpaths == ["libgmt.dylib" ]
88
- elif os_name == "win32" :
89
- assert lib_fullpaths == ["gmt.dll" , "gmt_w64.dll" , "gmt_w32.dll" ]
90
117
91
- bin_realpath = shutil .which ("gmt" )
92
- lib_realpath = subprocess .check_output (
93
- [bin_realpath , "--show-library" ], encoding = "utf-8"
94
- ).rstrip ("\n " )
95
-
96
- # 2. GMT_LIBRARY_PATH is defined but PATH is undefined
118
+ def test_clib_full_names_gmt_library_path_defined_path_empty (
119
+ monkeypatch , gmt_lib_names , gmt_lib_realpath
120
+ ):
121
+ """
122
+ Make sure that clib_full_names() returns a generator with expected names
123
+ when GMT_LIBRARY_PATH is defined and PATH is empty.
124
+ """
97
125
with monkeypatch .context () as mpatch :
98
- mpatch .setenv ("GMT_LIBRARY_PATH" , os .path .dirname (lib_realpath ))
126
+ mpatch .setenv ("GMT_LIBRARY_PATH" , os .path .dirname (gmt_lib_realpath ))
99
127
mpatch .setenv ("PATH" , "" )
100
128
129
+ lib_fullpaths = clib_full_names ()
130
+ assert isinstance (lib_fullpaths , types .GeneratorType )
131
+ assert list (lib_fullpaths ) == [gmt_lib_realpath ] + gmt_lib_names
132
+
133
+
134
+ def test_clib_full_names_gmt_library_path_undefined_path_included (
135
+ monkeypatch , gmt_lib_names , gmt_lib_realpath , gmt_bin_realpath , os_name
136
+ ):
137
+ """
138
+ Make sure that clib_full_names() returns a generator with expected names
139
+ when GMT_LIBRARY_PATH is undefined and PATH includes GMT's bin path.
140
+ """
141
+ with monkeypatch .context () as mpatch :
142
+ mpatch .delenv ("GMT_LIBRARY_PATH" , raising = False )
143
+ mpatch .setenv ("PATH" , os .path .dirname (gmt_bin_realpath ))
144
+
101
145
lib_fullpaths = clib_full_names ()
102
146
assert isinstance (lib_fullpaths , types .GeneratorType )
103
147
104
148
lib_fullpaths = list (lib_fullpaths )
105
- if os_name .startswith ("linux" ):
106
- assert lib_fullpaths == [lib_realpath , "libgmt.so" ]
107
- elif os_name == "darwin" :
108
- assert lib_fullpaths == [lib_realpath , "libgmt.dylib" ]
149
+ if os_name .startswith ("linux" ) or os_name == "darwin" :
150
+ assert lib_fullpaths == [gmt_lib_realpath ] + gmt_lib_names
109
151
elif os_name == "win32" :
110
- assert lib_fullpaths == [
111
- lib_realpath ,
112
- "gmt.dll" ,
113
- "gmt_w64.dll" ,
114
- "gmt_w32.dll" ,
115
- ]
116
-
117
- # 3. GMT_LIBRARY_PATH is undefined but PATH is defined
152
+ # On Windows: we also call find_library() to find the library in PATH
153
+ assert lib_fullpaths == [gmt_lib_realpath ] * 2 + gmt_lib_names
154
+
155
+
156
+ def test_clib_full_names_gmt_library_path_defined_path_included (
157
+ monkeypatch , gmt_lib_names , gmt_lib_realpath , gmt_bin_realpath , os_name
158
+ ):
159
+ """
160
+ Make sure that clib_full_names() returns a generator with expected names
161
+ when GMT_LIBRARY_PATH is defined and PATH includes GMT's bin path.
162
+ """
118
163
with monkeypatch .context () as mpatch :
119
- mpatch .delenv ("GMT_LIBRARY_PATH" , raising = False )
120
- mpatch .setenv ("PATH" , os .path .dirname (bin_realpath ))
164
+ mpatch .setenv ("GMT_LIBRARY_PATH" , os . path . dirname ( gmt_lib_realpath ) )
165
+ mpatch .setenv ("PATH" , os .path .dirname (gmt_bin_realpath ))
121
166
122
167
lib_fullpaths = clib_full_names ()
123
168
assert isinstance (lib_fullpaths , types .GeneratorType )
124
169
125
170
lib_fullpaths = list (lib_fullpaths )
126
- if os_name .startswith ("linux" ):
127
- assert lib_fullpaths == [lib_realpath , "libgmt.so" ]
128
- elif os_name == "darwin" :
129
- assert lib_fullpaths == [lib_realpath , "libgmt.dylib" ]
171
+ if os_name .startswith ("linux" ) or os_name == "darwin" :
172
+ assert lib_fullpaths == [gmt_lib_realpath ] * 2 + gmt_lib_names
130
173
elif os_name == "win32" :
131
- assert lib_fullpaths == [
132
- lib_realpath ,
133
- lib_realpath ,
134
- "gmt.dll" ,
135
- "gmt_w64.dll" ,
136
- "gmt_w32.dll" ,
137
- ]
138
-
139
- # 4. both GMT_LIBRARY_PATH and PATH are defined
174
+ assert lib_fullpaths == [gmt_lib_realpath ] * 3 + gmt_lib_names
175
+
176
+
177
+ def test_clib_full_names_gmt_library_path_incorrect_path_included (
178
+ monkeypatch , gmt_lib_names , gmt_lib_realpath , gmt_bin_realpath , os_name
179
+ ):
180
+ """
181
+ Make sure that clib_full_names() returns a generator with expected names
182
+ when GMT_LIBRARY_PATH is defined but incorrect and PATH includes GMT's bin path.
183
+ """
140
184
with monkeypatch .context () as mpatch :
141
- mpatch .setenv ("GMT_LIBRARY_PATH" , os . path . dirname ( lib_realpath ) )
142
- mpatch .setenv ("PATH" , os .path .dirname (bin_realpath ))
185
+ mpatch .setenv ("GMT_LIBRARY_PATH" , "/not/a/valid/library/ path" )
186
+ mpatch .setenv ("PATH" , os .path .dirname (gmt_bin_realpath ))
143
187
144
188
lib_fullpaths = clib_full_names ()
145
189
assert isinstance (lib_fullpaths , types .GeneratorType )
146
190
147
191
lib_fullpaths = list (lib_fullpaths )
148
- if os_name .startswith ("linux" ):
149
- assert lib_fullpaths == [lib_realpath , lib_realpath , "libgmt.so" ]
150
- elif os_name == "darwin" :
151
- assert lib_fullpaths == [lib_realpath , lib_realpath , "libgmt.dylib" ]
192
+ if os_name .startswith ("linux" ) or os_name == "darwin" :
193
+ assert lib_fullpaths == [gmt_lib_realpath ] + gmt_lib_names
152
194
elif os_name == "win32" :
153
- assert lib_fullpaths == [
154
- lib_realpath ,
155
- lib_realpath ,
156
- lib_realpath ,
157
- "gmt.dll" ,
158
- "gmt_w64.dll" ,
159
- "gmt_w32.dll" ,
160
- ]
195
+ assert lib_fullpaths == [gmt_lib_realpath ] * 2 + gmt_lib_names
0 commit comments