Skip to content

Commit 5787a34

Browse files
authored
Refactor tests to pass list of arguments to the Session.call_module method (#3256)
1 parent 8839e7b commit 5787a34

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

pygmt/tests/test_clib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_call_module_invalid_arguments():
181181
"""
182182
with clib.Session() as lib:
183183
with pytest.raises(GMTCLibError):
184-
lib.call_module("info", "bogus-data.bla")
184+
lib.call_module("info", ["bogus-data.bla"])
185185

186186

187187
def test_call_module_invalid_name():
@@ -190,7 +190,7 @@ def test_call_module_invalid_name():
190190
"""
191191
with clib.Session() as lib:
192192
with pytest.raises(GMTCLibError):
193-
lib.call_module("meh", "")
193+
lib.call_module("meh", [])
194194

195195

196196
def test_call_module_error_message():
@@ -199,7 +199,7 @@ def test_call_module_error_message():
199199
"""
200200
with clib.Session() as lib:
201201
with pytest.raises(GMTCLibError) as exc_info:
202-
lib.call_module("info", "bogus-data.bla")
202+
lib.call_module("info", ["bogus-data.bla"])
203203
assert "Module 'info' failed with status code" in exc_info.value.args[0]
204204
assert (
205205
"gmtinfo [ERROR]: Cannot find file bogus-data.bla" in exc_info.value.args[0]
@@ -213,7 +213,7 @@ def test_method_no_session():
213213
# Create an instance of Session without "with" so no session is created.
214214
lib = clib.Session()
215215
with pytest.raises(GMTCLibNoSessionError):
216-
lib.call_module("gmtdefaults", "")
216+
lib.call_module("gmtdefaults", [])
217217
with pytest.raises(GMTCLibNoSessionError):
218218
_ = lib.session_pointer
219219

@@ -385,14 +385,14 @@ def test_extract_region_two_figures():
385385
# Activate the first figure and extract the region from it
386386
# Use in a different session to avoid any memory problems.
387387
with clib.Session() as lib:
388-
lib.call_module("figure", f"{fig1._name} -")
388+
lib.call_module("figure", [fig1._name, "-"])
389389
with clib.Session() as lib:
390390
wesn1 = lib.extract_region()
391391
npt.assert_allclose(wesn1, region1)
392392

393393
# Now try it with the second one
394394
with clib.Session() as lib:
395-
lib.call_module("figure", f"{fig2._name} -")
395+
lib.call_module("figure", [fig2._name, "-"])
396396
with clib.Session() as lib:
397397
wesn2 = lib.extract_region()
398398
npt.assert_allclose(wesn2, np.array([-165.0, -150.0, 15.0, 25.0]))

pygmt/tests/test_clib_virtualfiles.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_virtual_file(dtypes):
6969
vfargs = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset)
7070
with lib.open_virtualfile(*vfargs) as vfile:
7171
with GMTTempFile() as outfile:
72-
lib.call_module("info", f"{vfile} ->{outfile.name}")
72+
lib.call_module("info", [vfile, f"->{outfile.name}"])
7373
output = outfile.read(keep_tabs=True)
7474
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
7575
expected = f"<matrix memory>: N = {shape[0]}\t{bounds}\n"
@@ -144,7 +144,7 @@ def test_virtualfile_in_required_z_matrix(array_func, kind):
144144
data=data, required_z=True, check_kind="vector"
145145
) as vfile:
146146
with GMTTempFile() as outfile:
147-
lib.call_module("info", f"{vfile} ->{outfile.name}")
147+
lib.call_module("info", [vfile, f"->{outfile.name}"])
148148
output = outfile.read(keep_tabs=True)
149149
bounds = "\t".join(
150150
[
@@ -217,7 +217,7 @@ def test_virtualfile_from_vectors(dtypes):
217217
with clib.Session() as lib:
218218
with lib.virtualfile_from_vectors(x, y, z) as vfile:
219219
with GMTTempFile() as outfile:
220-
lib.call_module("info", f"{vfile} ->{outfile.name}")
220+
lib.call_module("info", [vfile, f"->{outfile.name}"])
221221
output = outfile.read(keep_tabs=True)
222222
bounds = "\t".join([f"<{i.min():.0f}/{i.max():.0f}>" for i in (x, y, z)])
223223
expected = f"<vector memory>: N = {size}\t{bounds}\n"
@@ -237,7 +237,7 @@ def test_virtualfile_from_vectors_one_string_or_object_column(dtype):
237237
with clib.Session() as lib:
238238
with lib.virtualfile_from_vectors(x, y, strings) as vfile:
239239
with GMTTempFile() as outfile:
240-
lib.call_module("convert", f"{vfile} ->{outfile.name}")
240+
lib.call_module("convert", [vfile, f"->{outfile.name}"])
241241
output = outfile.read(keep_tabs=True)
242242
expected = "".join(
243243
f"{i}\t{j}\t{k}\n" for i, j, k in zip(x, y, strings, strict=True)
@@ -259,7 +259,7 @@ def test_virtualfile_from_vectors_two_string_or_object_columns(dtype):
259259
with clib.Session() as lib:
260260
with lib.virtualfile_from_vectors(x, y, strings1, strings2) as vfile:
261261
with GMTTempFile() as outfile:
262-
lib.call_module("convert", f"{vfile} ->{outfile.name}")
262+
lib.call_module("convert", [vfile, f"->{outfile.name}"])
263263
output = outfile.read(keep_tabs=True)
264264
expected = "".join(
265265
f"{h}\t{i}\t{j} {k}\n"
@@ -278,7 +278,7 @@ def test_virtualfile_from_vectors_transpose(dtypes):
278278
with clib.Session() as lib:
279279
with lib.virtualfile_from_vectors(*data.T) as vfile:
280280
with GMTTempFile() as outfile:
281-
lib.call_module("info", f"{vfile} -C ->{outfile.name}")
281+
lib.call_module("info", [vfile, "-C", f"->{outfile.name}"])
282282
output = outfile.read(keep_tabs=True)
283283
bounds = "\t".join([f"{col.min():.0f}\t{col.max():.0f}" for col in data.T])
284284
expected = f"{bounds}\n"
@@ -308,7 +308,7 @@ def test_virtualfile_from_matrix(dtypes):
308308
with clib.Session() as lib:
309309
with lib.virtualfile_from_matrix(data) as vfile:
310310
with GMTTempFile() as outfile:
311-
lib.call_module("info", f"{vfile} ->{outfile.name}")
311+
lib.call_module("info", [vfile, f"->{outfile.name}"])
312312
output = outfile.read(keep_tabs=True)
313313
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
314314
expected = f"<matrix memory>: N = {shape[0]}\t{bounds}\n"
@@ -328,7 +328,7 @@ def test_virtualfile_from_matrix_slice(dtypes):
328328
with clib.Session() as lib:
329329
with lib.virtualfile_from_matrix(data) as vfile:
330330
with GMTTempFile() as outfile:
331-
lib.call_module("info", f"{vfile} ->{outfile.name}")
331+
lib.call_module("info", [vfile, f"->{outfile.name}"])
332332
output = outfile.read(keep_tabs=True)
333333
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
334334
expected = f"<matrix memory>: N = {rows}\t{bounds}\n"
@@ -354,7 +354,7 @@ def test_virtualfile_from_vectors_pandas(dtypes_pandas):
354354
with clib.Session() as lib:
355355
with lib.virtualfile_from_vectors(data.x, data.y, data.z) as vfile:
356356
with GMTTempFile() as outfile:
357-
lib.call_module("info", f"{vfile} ->{outfile.name}")
357+
lib.call_module("info", [vfile, f"->{outfile.name}"])
358358
output = outfile.read(keep_tabs=True)
359359
bounds = "\t".join(
360360
[f"<{i.min():.0f}/{i.max():.0f}>" for i in (data.x, data.y, data.z)]
@@ -374,7 +374,7 @@ def test_virtualfile_from_vectors_arraylike():
374374
with clib.Session() as lib:
375375
with lib.virtualfile_from_vectors(x, y, z) as vfile:
376376
with GMTTempFile() as outfile:
377-
lib.call_module("info", f"{vfile} ->{outfile.name}")
377+
lib.call_module("info", [vfile, f"->{outfile.name}"])
378378
output = outfile.read(keep_tabs=True)
379379
bounds = "\t".join([f"<{min(i):.0f}/{max(i):.0f}>" for i in (x, y, z)])
380380
expected = f"<vector memory>: N = {size}\t{bounds}\n"

pygmt/tests/test_datatypes_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def dataframe_from_gmt(fname, **kwargs):
4646
"""
4747
with Session() as lib:
4848
with lib.virtualfile_out(kind="dataset") as vouttbl:
49-
lib.call_module("read", f"{fname} {vouttbl} -Td")
49+
lib.call_module("read", [fname, vouttbl, "-Td"])
5050
df = lib.virtualfile_to_dataset(vfname=vouttbl, **kwargs)
5151
return df
5252

pygmt/tests/test_session_management.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_begin_end():
2121
end() # Kill the global session
2222
begin()
2323
with Session() as lib:
24-
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
24+
lib.call_module("basemap", ["-R10/70/-3/8", "-JX4i/3i", "-Ba"])
2525
end()
2626
begin() # Restart the global session
2727
assert Path("pygmt-session.pdf").exists()
@@ -39,10 +39,10 @@ def test_gmt_compat_6_is_applied(capsys):
3939
# Generate a gmt.conf file in the current directory
4040
# with GMT_COMPATIBILITY = 5
4141
with Session() as lib:
42-
lib.call_module("gmtset", "GMT_COMPATIBILITY 5")
42+
lib.call_module("gmtset", ["GMT_COMPATIBILITY=5"])
4343
begin()
4444
with Session() as lib:
45-
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
45+
lib.call_module("basemap", ["-R10/70/-3/8", "-JX4i/3i", "-Ba"])
4646
out, err = capsys.readouterr() # capture stdout and stderr
4747
assert out == ""
4848
assert err != (

0 commit comments

Comments
 (0)