Skip to content

Commit bf7587c

Browse files
committed
Improve the tests for datetime strings
1 parent 10fb939 commit bf7587c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

pygmt/tests/test_clib_put_vector.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,17 @@ def test_put_vector_string_dtype():
109109
[-10, 30.5, -30.5, 40.508472], # longitudes
110110
[10, -30.50, 30.5, -40.508472], # latitudes
111111
# datetimes
112-
["2021-02-03", "2021-02-03T04", "2021-02-03T04:05:06.700", "T04:50:06.700"],
112+
[
113+
"2021-02-03T00:00:00",
114+
"2021-02-03T04:00:00",
115+
"2021-02-03T04:05:06",
116+
"2021-03-02T04:50:06",
117+
],
113118
]
114119

115120
expected_dtypes = [np.double, np.double, np.double, np.str_]
116121

117-
for i, j in itertools.combinations_with_replacement(range(3), r=2):
118-
# TODO: Change range(3) to range(4)
122+
for i, j in itertools.combinations_with_replacement(range(4), r=2):
119123
with clib.Session() as lib:
120124
dataset = lib.create_data(
121125
family="GMT_IS_DATASET|GMT_VIA_VECTOR",
@@ -138,12 +142,17 @@ def test_put_vector_string_dtype():
138142
dataset,
139143
)
140144
# Load the data and check that it's correct
141-
newx, newy = tmp_file.loadtxt(
142-
unpack=True,
143-
dtype=[("x", expected_dtypes[i]), ("y", expected_dtypes[j])],
145+
output = np.genfromtxt(
146+
tmp_file.name, dtype=None, names=("x", "y"), encoding=None
144147
)
145-
npt.assert_allclose(newx, expected_vectors[i])
146-
npt.assert_allclose(newy, expected_vectors[j])
148+
if i != 3:
149+
npt.assert_allclose(output["x"], expected_vectors[i])
150+
else:
151+
npt.assert_array_equal(output["x"], expected_vectors[i])
152+
if j != 3:
153+
npt.assert_allclose(output["y"], expected_vectors[j])
154+
else:
155+
npt.assert_array_equal(output["y"], expected_vectors[j])
147156

148157

149158
def test_put_vector_invalid_dtype():

0 commit comments

Comments
 (0)