Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen timer test #407

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions typhon/tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Testing the functions in typhon.utils.
"""
import warnings
import numpy
import numpy as np
import xarray
from time import sleep
from datetime import timedelta
Expand Down Expand Up @@ -35,19 +35,19 @@ def test_unique(self):

def test_undo_xarray_floatification(self):
ds = xarray.Dataset(
{"a": (["x"], numpy.array([1, 2, 3], dtype="f4")),
"b": (["x"], numpy.array([2.0, 3.0, 4.0])),
"c": (["x"], numpy.array(["2010-01-01", "2010-01-02",
{"a": (["x"], np.array([1, 2, 3], dtype="f4")),
"b": (["x"], np.array([2.0, 3.0, 4.0])),
"c": (["x"], np.array(["2010-01-01", "2010-01-02",
"2010-01-03"], dtype="M8"))})
ds["a"].encoding = {"dtype": numpy.dtype("i4"),
ds["a"].encoding = {"dtype": np.dtype("i4"),
"_FillValue": 1234}
# c should NOT be converted because it's a time
ds["c"].encoding = {"dtype": numpy.dtype("i8"),
ds["c"].encoding = {"dtype": np.dtype("i8"),
"_FillValue": 12345}
ds2 = utils.undo_xarray_floatification(ds)
assert ds is not ds2 # has to be a copy
assert ds["a"].encoding == ds2["a"].encoding
assert numpy.allclose(ds["a"], ds2["a"])
assert np.allclose(ds["a"], ds2["a"])
assert ds2["a"].dtype == ds2["a"].encoding["dtype"]
assert (ds2["c"] == ds["c"]).all()
assert ds2["c"].dtype == ds["c"].dtype
Expand All @@ -60,7 +60,7 @@ def test_Timer_methods(self):
sleep(0.05)
dt = t.stop()

assert timedelta(seconds=0.05) <= dt
assert dt.microseconds > 49_000

def test_Timer_block(self):
"""Test usage of a `Timer` object in a with-block."""
Expand Down