-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_psconvert.py
59 lines (50 loc) · 1.43 KB
/
test_psconvert.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
58
59
"""
Test Figure.psconvert.
"""
import os
import pytest
from pygmt import Figure
from pygmt.exceptions import GMTInvalidInput
def test_psconvert():
"""
Check that psconvert creates a figure in the current directory.
"""
fig = Figure()
fig.basemap(region="10/70/-3/8", projection="X4i/3i", frame="a")
prefix = "test_psconvert"
fig.psconvert(prefix=prefix, fmt="f", crop=True)
fname = prefix + ".pdf"
assert os.path.exists(fname)
os.remove(fname)
def test_psconvert_twice():
"""
Call psconvert twice to get two figures.
"""
fig = Figure()
fig.basemap(region="10/70/-3/8", projection="X4i/3i", frame="a")
prefix = "test_psconvert_twice"
# Make a PDF
fig.psconvert(prefix=prefix, fmt="f")
fname = prefix + ".pdf"
assert os.path.exists(fname)
os.remove(fname)
# Make a PNG
fig.psconvert(prefix=prefix, fmt="g")
fname = prefix + ".png"
assert os.path.exists(fname)
os.remove(fname)
def test_psconvert_without_prefix():
"""
Call psconvert without the 'prefix' parameter.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.psconvert(fmt="g")
@pytest.mark.parametrize("prefix", ["", None, False, True])
def test_psconvert_invalid_prefix(prefix):
"""
Call psconvert with an invalid 'prefix' argument.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.psconvert(fmt="g", prefix=prefix)