Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test with warning and fix resourcewarning #224

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions oct2py/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from __future__ import print_function, absolute_import, division

import atexit
import logging
import os
import os.path as osp
import shutil
import tempfile
import warnings

Expand Down Expand Up @@ -70,8 +72,9 @@ def __init__(self, logger=None, timeout=None,
self.timeout = timeout
self.backend = backend or 'default'
if temp_dir is None:
self.temp_dir_obj = tempfile.TemporaryDirectory()
self.temp_dir = self.temp_dir_obj.name
temp_dir_obj = tempfile.mkdtemp()
self.temp_dir = temp_dir_obj
atexit.register(shutil.rmtree, self.temp_dir)
else:
self.temp_dir = temp_dir
self.convert_to_float = convert_to_float
Expand Down
8 changes: 8 additions & 0 deletions oct2py/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,20 @@ def _encode(data, convert_to_float):

def _is_simple_numeric(data):
"""Test if a list contains simple numeric data."""
item_len = None
for item in data:
if isinstance(item, set):
item = list(item)
if isinstance(item, list):
if not _is_simple_numeric(item):
return False
# Numpy does not support creating an ndarray from
# ragged nested sequences
# (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes
if item_len is None:
item_len = len(item)
if len(item) != item_len:
return False
elif not isinstance(item, (int, float, complex)):
return False
return True
10 changes: 0 additions & 10 deletions oct2py/tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ def test_empty(self):
incoming[np.isfinite(incoming)])
assert type_ == 'double'

def test_mat(self):
'''Verify support for matrix type
'''
test = np.random.rand(1000)
test = np.mat(test)
incoming, type_ = self.oc.roundtrip(test, nout=2)
assert np.allclose(test, incoming)
assert test.dtype == incoming.dtype
assert type_ == 'double'

def test_masked(self):
'''Test support for masked arrays
'''
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ default = 0

[tool.pytest.ini_options]
testpaths = "oct2py"
addopts= "-raXs --durations 10 --color=yes --doctest-modules"
doctest_optionflags = "NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL"
timeout = 300
# Restore this setting to debug failures
# timeout_method = "thread"
filterwarnings= [
# Fail on warnings
"error",
# Ignore imp deprecation warnings from ipykernel
"ignore:the imp module is deprecated:DeprecationWarning",
# Ignore imp distutils warnings from ipykernel
"ignore:the distutils package is deprecated:DeprecationWarning",
# Ignore our own user warnings
"ignore:Using deprecated:UserWarning:oct2py",
"ignore:Key - value pairs:UserWarning:oct2py",
]
11 changes: 9 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ install_requires =
octave_kernel >= 0.34.0

[options.extras_require]
test = pytest;pandas;nbconvert
docs = sphinx;sphinx-bootstrap-theme;numpydoc
test =
pytest
pandas
nbconvert
pytest-timeout
docs =
sphinx
sphinx-bootstrap-theme
numpydoc

[bdist_wheel]
universal=1
Expand Down