Skip to content

Commit

Permalink
Mock X2SYS_HOME in a temporary X2SYS_TMP instead of current working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Sep 8, 2020
1 parent e8cb8b6 commit a64f47f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pygmt/tests/test_x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Tests for x2sys_cross
"""
import os
import shutil
from tempfile import TemporaryDirectory

import numpy as np
Expand All @@ -19,10 +20,14 @@
@pytest.fixture(name="mock_x2sys_home")
def fixture_mock_x2sys_home(monkeypatch):
"""
Set the X2SYS_HOME environment variable to the current working directory
for the test session
Set the X2SYS_HOME environment variable to "X2SYS_TMP" in the current
working directory for the test session
"""
monkeypatch.setenv("X2SYS_HOME", os.getcwd())
x2sys_home = os.path.join(os.getcwd(), "X2SYS_TMP")
os.makedirs(name=x2sys_home, exist_ok=True)
monkeypatch.setenv("X2SYS_HOME", x2sys_home)
yield x2sys_home
shutil.rmtree(x2sys_home) # cleanup X2SYS_TMP directory after tests


@pytest.fixture(scope="module", name="tracks")
Expand All @@ -39,7 +44,7 @@ def test_x2sys_cross_input_file_output_file(mock_x2sys_home):
Run x2sys_cross by passing in a filename, and output internal crossovers to
an ASCII txt file
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)
outfile = os.path.join(tmpdir, "tmp_coe.txt")
Expand All @@ -59,7 +64,7 @@ def test_x2sys_cross_input_file_output_dataframe(mock_x2sys_home):
Run x2sys_cross by passing in a filename, and output internal crossovers to
a pandas.DataFrame
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)
output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, coe="i", verbose="i")
Expand All @@ -79,7 +84,7 @@ def test_x2sys_cross_input_dataframe_output_dataframe(mock_x2sys_home, tracks):
to a pandas.DataFrame. Not actually implemented yet, wait for
https://github.com/GenericMappingTools/gmt/issues/3717
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)

Expand All @@ -102,7 +107,7 @@ def test_x2sys_cross_input_two_filenames(mock_x2sys_home):
Run x2sys_cross by passing in two filenames, and output external crossovers
to a pandas.DataFrame
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)

Expand Down Expand Up @@ -142,7 +147,7 @@ def test_x2sys_cross_region_interpolation_numpoints(mock_x2sys_home):
Test that x2sys_cross's region (R), interpolation (l) and numpoints (W)
arguments work.
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)
output = x2sys_cross(
Expand All @@ -165,7 +170,7 @@ def test_x2sys_cross_trackvalues(mock_x2sys_home):
"""
Test that x2sys_cross's trackvalues (Z) argument work.
"""
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
with TemporaryDirectory(prefix="X2SYS", dir=mock_x2sys_home) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)
output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, trackvalues=True)
Expand Down

0 comments on commit a64f47f

Please sign in to comment.