Skip to content

Commit c779d09

Browse files
committed
BUG: Conditional python 3.8 code optional
Make code imported from Python 3.8+ features an optional testcase. Resolves: #2963.
1 parent d85bb67 commit c779d09

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Modules/Filtering/Smoothing/wrapping/test/MedianImageFilterTest.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222

2323
import itk
2424
import itk.support.types as itkt
25-
from sys import argv
25+
from sys import argv, version_info
2626
import warnings
27-
from typing import Sequence, TypeVar, get_type_hints, get_args, get_origin, Union
27+
28+
if version_info >= (3, 8):
29+
from typing import Sequence, TypeVar, get_type_hints, get_args, get_origin, Union
30+
else:
31+
from typing import Sequence, TypeVar, Union
32+
2833

2934
try:
3035
from numpy.typing import ArrayLike
@@ -52,26 +57,27 @@
5257
compare_filter.Update()
5358
assert compare_filter.GetMaximumDifference() < 0.000000001
5459

55-
# Check the type hints
56-
type_hints = get_type_hints(itk.median_image_filter, globalns={"itk": itk})
60+
if version_info >= (3, 8):
61+
# Check the type hints
62+
type_hints = get_type_hints(itk.median_image_filter, globalns={"itk": itk})
5763

58-
assert "args" in type_hints
59-
args_hints = type_hints["args"]
60-
assert get_origin(args_hints) is Union
61-
assert itk.ImageBase in get_args(args_hints)
64+
assert "args" in type_hints
65+
args_hints = type_hints["args"]
66+
assert get_origin(args_hints) is Union
67+
assert itk.ImageBase in get_args(args_hints)
6268

63-
assert "radius" in type_hints
64-
radius_hints = type_hints["radius"]
65-
assert get_origin(radius_hints) is Union
66-
assert int in get_args(radius_hints)
67-
assert Sequence[int] in get_args(radius_hints)
69+
assert "radius" in type_hints
70+
radius_hints = type_hints["radius"]
71+
assert get_origin(radius_hints) is Union
72+
assert int in get_args(radius_hints)
73+
assert Sequence[int] in get_args(radius_hints)
6874

69-
assert "return" in type_hints
70-
result_hints = type_hints["return"]
71-
assert itk.ImageBase in get_args(args_hints)
75+
assert "return" in type_hints
76+
result_hints = type_hints["return"]
77+
assert itk.ImageBase in get_args(args_hints)
7278

73-
# Check for process_object attribute pointing to the associated class
74-
assert itk.median_image_filter.process_object is itk.MedianImageFilter
79+
# Check for process_object attribute pointing to the associated class
80+
assert itk.median_image_filter.process_object is itk.MedianImageFilter
7581

7682

7783
# Test that `__call__()` inside itkTemplate is deprecated. Replaced

0 commit comments

Comments
 (0)