2
2
Test pygmt.filter1d.
3
3
"""
4
4
5
- from pathlib import Path
6
-
7
- import numpy as np
8
5
import pandas as pd
9
6
import pytest
10
7
from pygmt import filter1d
11
8
from pygmt .datasets import load_sample_data
12
- from pygmt .exceptions import GMTInvalidInput
13
- from pygmt .helpers import GMTTempFile
14
9
15
10
16
11
@pytest .fixture (scope = "module" , name = "data" )
@@ -21,76 +16,11 @@ def fixture_data():
21
16
return load_sample_data (name = "maunaloa_co2" )
22
17
23
18
24
- def test_filter1d_no_outfile (data ):
19
+ @pytest .mark .benchmark
20
+ def test_filter1d (data ):
25
21
"""
26
- Test filter1d with no set outfile .
22
+ Test the basic functionality of filter1d .
27
23
"""
28
24
result = filter1d (data = data , filter_type = "g5" )
25
+ assert isinstance (result , pd .DataFrame )
29
26
assert result .shape == (671 , 2 )
30
-
31
-
32
- def test_filter1d_file_output (data ):
33
- """
34
- Test that filter1d returns a file output when it is specified.
35
- """
36
- with GMTTempFile (suffix = ".txt" ) as tmpfile :
37
- result = filter1d (
38
- data = data , filter_type = "g5" , outfile = tmpfile .name , output_type = "file"
39
- )
40
- assert result is None # return value is None
41
- assert Path (tmpfile .name ).stat ().st_size > 0 # check that outfile exists
42
-
43
-
44
- def test_filter1d_invalid_format (data ):
45
- """
46
- Test that filter1d fails with an incorrect format for output_type.
47
- """
48
- with pytest .raises (GMTInvalidInput ):
49
- filter1d (data = data , filter_type = "g5" , output_type = "a" )
50
-
51
-
52
- def test_filter1d_no_filter (data ):
53
- """
54
- Test that filter1d fails with an argument is missing for filter.
55
- """
56
- with pytest .raises (GMTInvalidInput ):
57
- filter1d (data = data )
58
-
59
-
60
- def test_filter1d_no_outfile_specified (data ):
61
- """
62
- Test that filter1d fails when outpput_type is set to 'file' but no output file name
63
- is specified.
64
- """
65
- with pytest .raises (GMTInvalidInput ):
66
- filter1d (data = data , filter_type = "g5" , output_type = "file" )
67
-
68
-
69
- def test_filter1d_outfile_incorrect_output_type (data ):
70
- """
71
- Test that filter1d raises a warning when an outfile filename is set but the
72
- output_type is not set to 'file'.
73
- """
74
- with pytest .warns (RuntimeWarning ):
75
- with GMTTempFile (suffix = ".txt" ) as tmpfile :
76
- result = filter1d (
77
- data = data , filter_type = "g5" , outfile = tmpfile .name , output_type = "numpy"
78
- )
79
- assert result is None # return value is None
80
- assert Path (tmpfile .name ).stat ().st_size > 0 # check that outfile exists
81
-
82
-
83
- @pytest .mark .benchmark
84
- def test_filter1d_format (data ):
85
- """
86
- Test that correct formats are returned.
87
- """
88
- time_series_default = filter1d (data = data , filter_type = "g5" )
89
- assert isinstance (time_series_default , pd .DataFrame )
90
- assert time_series_default .shape == (671 , 2 )
91
- time_series_array = filter1d (data = data , filter_type = "g5" , output_type = "numpy" )
92
- assert isinstance (time_series_array , np .ndarray )
93
- assert time_series_array .shape == (671 , 2 )
94
- time_series_df = filter1d (data = data , filter_type = "g5" , output_type = "pandas" )
95
- assert isinstance (time_series_df , pd .DataFrame )
96
- assert time_series_df .shape == (671 , 2 )
0 commit comments