Skip to content

Commit 5a7006f

Browse files
committed
tests: Add unittest.skipIf() wrapper that works on Python 2.6
1 parent 9f514ee commit 5a7006f

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,32 @@
1717
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
#
1919

20+
from functools import wraps
2021
import os
22+
import unittest
23+
24+
try:
25+
import openslide._convert as _
26+
have_optimizations = True
27+
except ImportError:
28+
have_optimizations = False
29+
2130

2231
def file_path(name):
2332
return os.path.join(os.path.dirname(__file__), name)
33+
34+
35+
def skip_if(condition, reason):
36+
if hasattr(unittest, 'skipIf'):
37+
# Python >= 2.7
38+
return unittest.skipIf(condition, reason)
39+
else:
40+
# Python 2.6
41+
def decorator(f):
42+
@wraps(f)
43+
def wrapper(*args, **kwargs):
44+
if condition:
45+
return
46+
return f(*args, **kwargs)
47+
return wrapper
48+
return decorator

tests/test_openslide.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import re
2424
import unittest
2525

26-
from . import file_path
26+
from . import file_path, have_optimizations, skip_if
2727

2828
# Tests should be written to be compatible with Python 2.6 unittest.
2929

@@ -125,12 +125,8 @@ def test_read_region_2GB(self):
125125
self.osr.read_region((1000, 1000), 0, (32768, 16384)).size,
126126
(32768, 16384))
127127

128+
@skip_if(have_optimizations, 'only relevant --without-performance')
128129
def test_read_region_2GB_width(self):
129-
try:
130-
import openslide._convert
131-
return
132-
except ImportError:
133-
pass
134130
self.assertRaises(ValueError,
135131
lambda: self.osr.read_region((1000, 1000), 0, (1 << 29, 1)))
136132

0 commit comments

Comments
 (0)