@@ -1613,7 +1613,7 @@ def virtualfile_from_data( # noqa: PLR0912
16131613 def virtualfile_out (
16141614 self , kind : Literal ["dataset" , "grid" ] = "dataset" , fname : str | None = None
16151615 ):
1616- """
1616+ r """
16171617 Create a virtual file or an actual file for storing output data.
16181618
16191619 If ``fname`` is not given, a virtual file will be created to store the output
@@ -1642,23 +1642,25 @@ def virtualfile_out(
16421642 >>> from pygmt.datatypes import _GMT_DATASET
16431643 >>> from pygmt.helpers import GMTTempFile
16441644 >>>
1645- >>> # Create a virtual file for storing the output table.
16461645 >>> with GMTTempFile(suffix=".txt") as tmpfile:
16471646 ... with open(tmpfile.name, mode="w") as fp:
16481647 ... print("1.0 2.0 3.0 TEXT", file=fp)
1648+ ...
1649+ ... # Create a virtual file for storing the output table.
16491650 ... with Session() as lib:
16501651 ... with lib.virtualfile_out(kind="dataset") as vouttbl:
16511652 ... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
16521653 ... ds = lib.read_virtualfile(vouttbl, kind="dataset")
1653- >>> isinstance(ds.contents, _GMT_DATASET)
1654- True
1655- >>> # Write data to an actual file without creating a virtual file.
1656- >>> with GMTTempFile(suffix=".nc") as tmpfile:
1654+ ... assert isinstance(ds.contents, _GMT_DATASET)
1655+ ...
1656+ ... # Write data to an actual file without creating a virtual file.
16571657 ... with Session() as lib:
1658- ... with lib.virtualfile_out(fname=tmpfile.name) as voutgrd:
1659- ... assert voutgrd == tmpfile.name
1660- ... lib.call_module("read", f"@earth_relief_01d_g {voutgrd} -Tg")
1661- ... assert Path(voutgrd).stat().st_size > 0
1658+ ... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
1659+ ... assert vouttbl == tmpfile.name
1660+ ... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1661+ ... with open(vouttbl, mode="r") as fp:
1662+ ... line = fp.readline()
1663+ ... assert line == "1\t2\t3\tTEXT\n"
16621664 """
16631665 if fname is not None : # Yield the actual file name.
16641666 yield fname
0 commit comments