Skip to content

Commit

Permalink
Restore global state modified during tests
Browse files Browse the repository at this point in the history
Specifically, numpy's error handling settings and yt's logging level.
  • Loading branch information
yut23 committed Sep 27, 2023
1 parent 96f8594 commit 65d9946
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 8 additions & 0 deletions yt/data_objects/tests/test_image_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
from yt.data_objects.image_array import ImageArray
from yt.testing import requires_module

old_settings = None


def setup():
global old_settings
from yt.config import ytcfg

ytcfg["yt", "internals", "within_testing"] = True
old_settings = np.geterr()
np.seterr(all="ignore")


def teardown():
np.seterr(**old_settings)


def dummy_image(kstep, nlayers):
im = np.zeros([64, 128, nlayers])
for i in range(im.shape[0]):
Expand Down
9 changes: 7 additions & 2 deletions yt/utilities/lib/tests/test_alt_ray_tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from yt.testing import amrspace
from yt.utilities.lib.alt_ray_tracers import _cyl2cart, cylindrical_ray_trace

left_grid = right_grid = amr_levels = center_grid = data = None
left_grid = right_grid = amr_levels = center_grid = data = old_settings = None


def setup():
# set up some sample cylindrical grid data, radiating out from center
global left_grid, right_grid, amr_levels, center_grid, data
global left_grid, right_grid, amr_levels, center_grid, data, old_settings
old_settings = np.geterr()
np.seterr(all="ignore")
l1, r1, lvl1 = amrspace([0.0, 1.0, 0.0, -1.0, 0.0, 2 * np.pi], levels=(7, 7, 0))
l2, r2, lvl2 = amrspace([0.0, 1.0, 0.0, 1.0, 0.0, 2 * np.pi], levels=(7, 7, 0))
Expand All @@ -21,6 +22,10 @@ def setup():
data = np.cos(np.sqrt(np.sum(center_grid[:, :2] ** 2, axis=1))) ** 2 # cos^2


def teardown():
np.seterr(**old_settings)


point_pairs = np.array(
[
# p1 p2
Expand Down
13 changes: 13 additions & 0 deletions yt/utilities/tests/test_set_log_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

from yt.utilities.logger import set_log_level

old_level = None


def setup():
global old_level
from yt.utilities.logger import ytLogger

old_level = ytLogger.level


def teardown():
set_log_level(old_level)


def test_valid_level():
# test a subset of valid entries to cover
Expand Down

0 comments on commit 65d9946

Please sign in to comment.