summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_format.py
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-08 23:49:17 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-15 13:19:56 -0800
commit1427484e9015e73b7017ee9336ce914a6f15187b (patch)
tree2db89078addee6a01697ab8bd4160c25d59fffc4 /numpy/lib/tests/test_format.py
parentb6bc0941d4f07310456079ab2497c3d1bde4a5e7 (diff)
downloadnumpy-1427484e9015e73b7017ee9336ce914a6f15187b.tar.gz
MAINT: Remove sys.version checks in tests
Diffstat (limited to 'numpy/lib/tests/test_format.py')
-rw-r--r--numpy/lib/tests/test_format.py59
1 files changed, 23 insertions, 36 deletions
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 28ce038ae..24593d7b3 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -548,10 +548,7 @@ def test_load_padded_dtype(dt):
def test_python2_python3_interoperability():
- if sys.version_info[0] >= 3:
- fname = 'win64python2.npy'
- else:
- fname = 'python3.npy'
+ fname = 'win64python2.npy'
path = os.path.join(os.path.dirname(__file__), 'data', fname)
data = np.load(path)
assert_array_equal(data, np.ones(2))
@@ -561,13 +558,7 @@ def test_pickle_python2_python3():
# Python 2 and Python 3 and vice versa
data_dir = os.path.join(os.path.dirname(__file__), 'data')
- if sys.version_info[0] >= 3:
- xrange = range
- else:
- import __builtin__
- xrange = __builtin__.xrange
-
- expected = np.array([None, xrange, u'\u512a\u826f',
+ expected = np.array([None, range, u'\u512a\u826f',
b'\xe4\xb8\x8d\xe8\x89\xaf'],
dtype=object)
@@ -583,34 +574,30 @@ def test_pickle_python2_python3():
else:
data = data_f
- if sys.version_info[0] >= 3:
- if encoding == 'latin1' and fname.startswith('py2'):
- assert_(isinstance(data[3], str))
- assert_array_equal(data[:-1], expected[:-1])
- # mojibake occurs
- assert_array_equal(data[-1].encode(encoding), expected[-1])
- else:
- assert_(isinstance(data[3], bytes))
- assert_array_equal(data, expected)
+ if encoding == 'latin1' and fname.startswith('py2'):
+ assert_(isinstance(data[3], str))
+ assert_array_equal(data[:-1], expected[:-1])
+ # mojibake occurs
+ assert_array_equal(data[-1].encode(encoding), expected[-1])
else:
+ assert_(isinstance(data[3], bytes))
assert_array_equal(data, expected)
- if sys.version_info[0] >= 3:
- if fname.startswith('py2'):
- if fname.endswith('.npz'):
- data = np.load(path, allow_pickle=True)
- assert_raises(UnicodeError, data.__getitem__, 'x')
- data.close()
- data = np.load(path, allow_pickle=True, fix_imports=False,
- encoding='latin1')
- assert_raises(ImportError, data.__getitem__, 'x')
- data.close()
- else:
- assert_raises(UnicodeError, np.load, path,
- allow_pickle=True)
- assert_raises(ImportError, np.load, path,
- allow_pickle=True, fix_imports=False,
- encoding='latin1')
+ if fname.startswith('py2'):
+ if fname.endswith('.npz'):
+ data = np.load(path, allow_pickle=True)
+ assert_raises(UnicodeError, data.__getitem__, 'x')
+ data.close()
+ data = np.load(path, allow_pickle=True, fix_imports=False,
+ encoding='latin1')
+ assert_raises(ImportError, data.__getitem__, 'x')
+ data.close()
+ else:
+ assert_raises(UnicodeError, np.load, path,
+ allow_pickle=True)
+ assert_raises(ImportError, np.load, path,
+ allow_pickle=True, fix_imports=False,
+ encoding='latin1')
def test_pickle_disallow():