summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2020-07-28 15:43:38 +0300
committermattip <matti.picus@gmail.com>2020-07-30 00:08:35 +0300
commitcf5e7665fdd764a6647f2b62d2740bb431180794 (patch)
treec3604726e27588507cba43e32c5312eb9260f31e
parentd28ac9aa5e2158f8418d446b55cff5772392c35f (diff)
downloadnumpy-cf5e7665fdd764a6647f2b62d2740bb431180794.tar.gz
TST: fix tests for windows + PyPy
-rw-r--r--numpy/core/tests/test_memmap.py7
-rw-r--r--numpy/distutils/mingw32ccompiler.py24
-rw-r--r--numpy/lib/tests/test_format.py41
-rw-r--r--numpy/lib/tests/test_io.py9
-rw-r--r--numpy/testing/_private/utils.py3
5 files changed, 55 insertions, 29 deletions
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index feef80ce8..a1e0c8f8f 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -11,7 +11,8 @@ from numpy import (
from numpy import arange, allclose, asarray
from numpy.testing import (
- assert_, assert_equal, assert_array_equal, suppress_warnings
+ assert_, assert_equal, assert_array_equal, suppress_warnings, IS_PYPY,
+ break_cycles
)
class TestMemmap:
@@ -25,6 +26,10 @@ class TestMemmap:
def teardown(self):
self.tmpfp.close()
+ self.data = None
+ if IS_PYPY:
+ break_cycles()
+ break_cycles()
shutil.rmtree(self.tempdir)
def test_roundtrip(self):
diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py
index 7cb6fadcc..3358695a8 100644
--- a/numpy/distutils/mingw32ccompiler.py
+++ b/numpy/distutils/mingw32ccompiler.py
@@ -8,6 +8,7 @@ Support code for building Python extensions on Windows.
"""
import os
+import platform
import sys
import subprocess
import re
@@ -265,16 +266,19 @@ def find_python_dll():
# search in the file system for possible candidates
major_version, minor_version = tuple(sys.version_info[:2])
- patterns = ['python%d%d.dll']
-
- for pat in patterns:
- dllname = pat % (major_version, minor_version)
- print("Looking for %s" % dllname)
- for folder in lib_dirs:
- dll = os.path.join(folder, dllname)
- if os.path.exists(dll):
- return dll
-
+ implementation = platform.python_implementation()
+ if implementation == 'CPython':
+ dllname = f'python{major_version}{minor_version}.dll'
+ elif implementation == 'PyPy':
+ dllname = f'libpypy{major_version}-c.dll'
+ else:
+ dllname = 'Unknown platform {implementation}'
+ print("Looking for %s" % dllname)
+ for folder in lib_dirs:
+ dll = os.path.join(folder, dllname)
+ if os.path.exists(dll):
+ return dll
+
raise ValueError("%s not found in %s" % (dllname, lib_dirs))
def dump_table(dll):
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 2dbaeb8cb..1bfd63bba 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -285,7 +285,7 @@ from io import BytesIO
import numpy as np
from numpy.testing import (
assert_, assert_array_equal, assert_raises, assert_raises_regex,
- assert_warns
+ assert_warns, IS_PYPY, break_cycles
)
from numpy.lib import format
@@ -488,11 +488,8 @@ def test_memmap_roundtrip():
# Write it out normally and through mmap.
nfn = os.path.join(tempdir, 'normal.npy')
mfn = os.path.join(tempdir, 'memmap.npy')
- fp = open(nfn, 'wb')
- try:
+ with open(nfn, 'wb') as fp:
format.write_array(fp, arr)
- finally:
- fp.close()
fortran_order = (
arr.flags.f_contiguous and not arr.flags.c_contiguous)
@@ -500,26 +497,29 @@ def test_memmap_roundtrip():
shape=arr.shape, fortran_order=fortran_order)
ma[...] = arr
del ma
+ if IS_PYPY:
+ break_cycles()
# Check that both of these files' contents are the same.
- fp = open(nfn, 'rb')
- normal_bytes = fp.read()
- fp.close()
- fp = open(mfn, 'rb')
- memmap_bytes = fp.read()
- fp.close()
+ with open(nfn, 'rb') as fp:
+ normal_bytes = fp.read()
+ with open(mfn, 'rb') as fp:
+ memmap_bytes = fp.read()
assert_equal_(normal_bytes, memmap_bytes)
# Check that reading the file using memmap works.
ma = format.open_memmap(nfn, mode='r')
del ma
+ if IS_PYPY:
+ break_cycles()
def test_compressed_roundtrip():
arr = np.random.rand(200, 200)
npz_file = os.path.join(tempdir, 'compressed.npz')
np.savez_compressed(npz_file, arr=arr)
- arr1 = np.load(npz_file)['arr']
+ with np.load(npz_file) as npz:
+ arr1 = npz['arr']
assert_array_equal(arr, arr1)
@@ -545,7 +545,8 @@ def test_load_padded_dtype(dt):
arr[i] = i + 5
npz_file = os.path.join(tempdir, 'aligned.npz')
np.savez(npz_file, arr=arr)
- arr1 = np.load(npz_file)['arr']
+ with np.load(npz_file) as npz:
+ arr1 = npz['arr']
assert_array_equal(arr, arr1)
@@ -610,8 +611,8 @@ def test_pickle_disallow():
allow_pickle=False, encoding='latin1')
path = os.path.join(data_dir, 'py2-objarr.npz')
- f = np.load(path, allow_pickle=False, encoding='latin1')
- assert_raises(ValueError, f.__getitem__, 'x')
+ with np.load(path, allow_pickle=False, encoding='latin1') as f:
+ assert_raises(ValueError, f.__getitem__, 'x')
path = os.path.join(tempdir, 'pickle-disabled.npy')
assert_raises(ValueError, np.save, path, np.array([None], dtype=object),
@@ -713,6 +714,8 @@ def test_version_2_0_memmap():
shape=d.shape, version=(2, 0))
ma[...] = d
del ma
+ if IS_PYPY:
+ break_cycles()
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', UserWarning)
@@ -721,9 +724,14 @@ def test_version_2_0_memmap():
assert_(w[0].category is UserWarning)
ma[...] = d
del ma
+ if IS_PYPY:
+ break_cycles()
ma = format.open_memmap(tf, mode='r')
assert_array_equal(ma, d)
+ del ma
+ if IS_PYPY:
+ break_cycles()
def test_write_version():
@@ -925,7 +933,8 @@ def test_empty_npz():
# Test for gh-9989
fname = os.path.join(tempdir, "nothing.npz")
np.savez(fname)
- np.load(fname)
+ with np.load(fname) as nps:
+ pass
def test_unicode_field_names():
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 959e63fa2..a23c6b007 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -24,7 +24,8 @@ from numpy.ma.testutils import assert_equal
from numpy.testing import (
assert_warns, assert_, assert_raises_regex, assert_raises,
assert_allclose, assert_array_equal, temppath, tempdir, IS_PYPY,
- HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, assert_no_warnings
+ HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, assert_no_warnings,
+ break_cycles
)
from numpy.testing._private.utils import requires_memory
@@ -2387,6 +2388,9 @@ class TestPathUsage:
assert_array_equal(data, a)
# close the mem-mapped file
del data
+ if IS_PYPY:
+ break_cycles()
+ break_cycles()
def test_save_load_memmap_readwrite(self):
# Test that pathlib.Path instances can be written mem-mapped.
@@ -2398,6 +2402,9 @@ class TestPathUsage:
a[0][0] = 5
b[0][0] = 5
del b # closes the file
+ if IS_PYPY:
+ break_cycles()
+ break_cycles()
data = np.load(path)
assert_array_equal(data, a)
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 3827b7505..4fc22dceb 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -2403,7 +2403,8 @@ def break_cycles():
if IS_PYPY:
# interpreter runs now, to call deleted objects' __del__ methods
gc.collect()
- # one more, just to make sure
+ # two more, just to make sure
+ gc.collect()
gc.collect()