-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_x2sys_init.py
57 lines (48 loc) · 1.63 KB
/
test_x2sys_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Test pygmt.x2sys_init.
"""
from pathlib import Path
from tempfile import TemporaryDirectory
import pytest
from pygmt import x2sys_init
@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.
"""
monkeypatch.setenv("X2SYS_HOME", str(Path.cwd()))
@pytest.mark.usefixtures("mock_x2sys_home")
def test_x2sys_init_region_spacing():
"""
Test that x2sys_init's region (R) and spacing (I) sequence arguments accept a list
properly.
"""
with TemporaryDirectory(prefix="X2SYS", dir=Path.cwd()) as tmpdir:
tmpdir_p = Path(tmpdir)
tag = tmpdir_p.name
x2sys_init(
tag=tag, fmtfile="xyz", force=True, region=[0, 10, 20, 30], spacing=[5, 5]
)
tail_line = (tmpdir_p / f"{tag}.tag").read_text().splitlines()[-1]
assert "-R0/10/20/30" in tail_line
assert "-I5/5" in tail_line
@pytest.mark.benchmark
@pytest.mark.usefixtures("mock_x2sys_home")
def test_x2sys_init_units_gap():
"""
Test that x2sys_init's units (N) and gap (W) arguments accept a list properly.
"""
with TemporaryDirectory(prefix="X2SYS", dir=Path.cwd()) as tmpdir:
tmpdir_p = Path(tmpdir)
tag = tmpdir_p.name
x2sys_init(
tag=tag,
fmtfile="xyz",
force=True,
units=["de", "se"],
gap=["tseconds", "de"],
)
tail_line = (tmpdir_p / f"{tag}.tag").read_text().splitlines()[-1]
assert "-Nse -Nde" in tail_line
assert "-Wtseconds -Wde" in tail_line