Skip to content

Commit f879473

Browse files
committed
PY36: Backport nullcontext
1 parent d4f2216 commit f879473

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

nibabel/testing/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
from itertools import zip_longest
2626

27+
try:
28+
from contextlib import nullcontext
29+
except ImportError: # PY36
30+
from contextlib import contextmanager
31+
@contextmanager
32+
def nullcontext():
33+
yield
34+
2735

2836
def test_data(subdir=None, fname=None):
2937
if subdir is None:

nibabel/tests/test_image_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import warnings
2727
from functools import partial
2828
from itertools import product
29-
from contextlib import nullcontext
3029
import pathlib
3130

3231
import numpy as np
@@ -46,8 +45,8 @@
4645
import pytest
4746

4847
from numpy.testing import assert_almost_equal, assert_array_equal, assert_warns, assert_allclose
49-
from ..testing import (bytesio_round_trip, bytesio_filemap,
50-
assert_data_similar, clear_and_catch_warnings)
48+
from nibabel.testing import (bytesio_round_trip, bytesio_filemap, assert_data_similar,
49+
clear_and_catch_warnings, nullcontext)
5150
from ..tmpdirs import InTemporaryDirectory
5251
from ..deprecator import ExpiredDeprecationError
5352

nibabel/tests/test_volumeutils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import bz2
2121
import threading
2222
import time
23-
from contextlib import nullcontext
2423

2524
import numpy as np
2625

@@ -58,7 +57,7 @@
5857
assert_array_equal)
5958
import pytest
6059

61-
from ..testing import assert_dt_equal, assert_allclose_safely, suppress_warnings
60+
from nibabel.testing import nullcontext, assert_dt_equal, assert_allclose_safely, suppress_warnings
6261

6362
#: convenience variables for numpy types
6463
FLOAT_TYPES = np.sctypes['float']

0 commit comments

Comments
 (0)