Skip to content

Refactor tests to pass list of arguments to the Session.call_module method #3256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_call_module_invalid_arguments():
"""
with clib.Session() as lib:
with pytest.raises(GMTCLibError):
lib.call_module("info", "bogus-data.bla")
lib.call_module("info", ["bogus-data.bla"])


def test_call_module_invalid_name():
Expand All @@ -190,7 +190,7 @@ def test_call_module_invalid_name():
"""
with clib.Session() as lib:
with pytest.raises(GMTCLibError):
lib.call_module("meh", "")
lib.call_module("meh", [])


def test_call_module_error_message():
Expand All @@ -199,7 +199,7 @@ def test_call_module_error_message():
"""
with clib.Session() as lib:
with pytest.raises(GMTCLibError) as exc_info:
lib.call_module("info", "bogus-data.bla")
lib.call_module("info", ["bogus-data.bla"])
assert "Module 'info' failed with status code" in exc_info.value.args[0]
assert (
"gmtinfo [ERROR]: Cannot find file bogus-data.bla" in exc_info.value.args[0]
Expand All @@ -213,7 +213,7 @@ def test_method_no_session():
# Create an instance of Session without "with" so no session is created.
lib = clib.Session()
with pytest.raises(GMTCLibNoSessionError):
lib.call_module("gmtdefaults", "")
lib.call_module("gmtdefaults", [])
with pytest.raises(GMTCLibNoSessionError):
_ = lib.session_pointer

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

# Now try it with the second one
with clib.Session() as lib:
lib.call_module("figure", f"{fig2._name} -")
lib.call_module("figure", [fig2._name, "-"])
with clib.Session() as lib:
wesn2 = lib.extract_region()
npt.assert_allclose(wesn2, np.array([-165.0, -150.0, 15.0, 25.0]))
Expand Down
20 changes: 10 additions & 10 deletions pygmt/tests/test_clib_virtualfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_virtual_file(dtypes):
vfargs = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset)
with lib.open_virtualfile(*vfargs) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
expected = f"<matrix memory>: N = {shape[0]}\t{bounds}\n"
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_virtualfile_in_required_z_matrix(array_func, kind):
data=data, required_z=True, check_kind="vector"
) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join(
[
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_virtualfile_from_vectors(dtypes):
with clib.Session() as lib:
with lib.virtualfile_from_vectors(x, y, z) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"<{i.min():.0f}/{i.max():.0f}>" for i in (x, y, z)])
expected = f"<vector memory>: N = {size}\t{bounds}\n"
Expand All @@ -237,7 +237,7 @@ def test_virtualfile_from_vectors_one_string_or_object_column(dtype):
with clib.Session() as lib:
with lib.virtualfile_from_vectors(x, y, strings) as vfile:
with GMTTempFile() as outfile:
lib.call_module("convert", f"{vfile} ->{outfile.name}")
lib.call_module("convert", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
expected = "".join(
f"{i}\t{j}\t{k}\n" for i, j, k in zip(x, y, strings, strict=True)
Expand All @@ -259,7 +259,7 @@ def test_virtualfile_from_vectors_two_string_or_object_columns(dtype):
with clib.Session() as lib:
with lib.virtualfile_from_vectors(x, y, strings1, strings2) as vfile:
with GMTTempFile() as outfile:
lib.call_module("convert", f"{vfile} ->{outfile.name}")
lib.call_module("convert", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
expected = "".join(
f"{h}\t{i}\t{j} {k}\n"
Expand All @@ -278,7 +278,7 @@ def test_virtualfile_from_vectors_transpose(dtypes):
with clib.Session() as lib:
with lib.virtualfile_from_vectors(*data.T) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} -C ->{outfile.name}")
lib.call_module("info", [vfile, "-C", f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"{col.min():.0f}\t{col.max():.0f}" for col in data.T])
expected = f"{bounds}\n"
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_virtualfile_from_matrix(dtypes):
with clib.Session() as lib:
with lib.virtualfile_from_matrix(data) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
expected = f"<matrix memory>: N = {shape[0]}\t{bounds}\n"
Expand All @@ -328,7 +328,7 @@ def test_virtualfile_from_matrix_slice(dtypes):
with clib.Session() as lib:
with lib.virtualfile_from_matrix(data) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T])
expected = f"<matrix memory>: N = {rows}\t{bounds}\n"
Expand All @@ -354,7 +354,7 @@ def test_virtualfile_from_vectors_pandas(dtypes_pandas):
with clib.Session() as lib:
with lib.virtualfile_from_vectors(data.x, data.y, data.z) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join(
[f"<{i.min():.0f}/{i.max():.0f}>" for i in (data.x, data.y, data.z)]
Expand All @@ -374,7 +374,7 @@ def test_virtualfile_from_vectors_arraylike():
with clib.Session() as lib:
with lib.virtualfile_from_vectors(x, y, z) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join([f"<{min(i):.0f}/{max(i):.0f}>" for i in (x, y, z)])
expected = f"<vector memory>: N = {size}\t{bounds}\n"
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_datatypes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def dataframe_from_gmt(fname, **kwargs):
"""
with Session() as lib:
with lib.virtualfile_out(kind="dataset") as vouttbl:
lib.call_module("read", f"{fname} {vouttbl} -Td")
lib.call_module("read", [fname, vouttbl, "-Td"])
df = lib.virtualfile_to_dataset(vfname=vouttbl, **kwargs)
return df

Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_begin_end():
end() # Kill the global session
begin()
with Session() as lib:
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
lib.call_module("basemap", ["-R10/70/-3/8", "-JX4i/3i", "-Ba"])
end()
begin() # Restart the global session
assert Path("pygmt-session.pdf").exists()
Expand All @@ -39,10 +39,10 @@ def test_gmt_compat_6_is_applied(capsys):
# Generate a gmt.conf file in the current directory
# with GMT_COMPATIBILITY = 5
with Session() as lib:
lib.call_module("gmtset", "GMT_COMPATIBILITY 5")
lib.call_module("gmtset", ["GMT_COMPATIBILITY=5"])
begin()
with Session() as lib:
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
lib.call_module("basemap", ["-R10/70/-3/8", "-JX4i/3i", "-Ba"])
out, err = capsys.readouterr() # capture stdout and stderr
assert out == ""
assert err != (
Expand Down
Loading