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

Update dependencies and fix style issues #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 15 additions & 9 deletions .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ contributors_rst: {}

manifest_in: {}

version_py:
major: 1
minor: 0
patch: 1
release: false

setup_py:
python_requires: ">=3.5"
install_req:
- numpy>=1.11
- numpy>=1.19
- pytest
docs_req:
- nbsphinx>=0.6.0
Expand All @@ -37,9 +42,12 @@ setup_py:
- "Development Status :: 5 - Production/Stable"
- "Framework :: Pytest"
- "Programming Language :: Python :: 3 :: Only"
- "Programming Language :: Python :: 3.5"
- "Programming Language :: Python :: 3.6"
- "Programming Language :: Python :: 3.7"
- "Programming Language :: Python :: 3.8"
- "Programming Language :: Python :: 3.9"
- "Programming Language :: Python :: 3.10"


setup_cfg:
pytest:
Expand Down Expand Up @@ -71,15 +79,13 @@ travis_yml:
- script: static
- script: test-coverage
- script: test
python: 3.5
python: 3.8
env:
NUMPY: numpy==1.11
NUMPY: numpy==1.19
cache: false # disable the cache for one build to make sure that works
- script: test
python: 3.7
dist: xenial # currently only xenial has python 3.7
env:
NUMPY: numpy==1.16
python: 3.10
dist: focal
- script: docs
pypi_user: tbekolay
deploy_dists:
Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ jobs:
SCRIPT="test-coverage"
-
env:
NUMPY="numpy==1.11"
NUMPY="numpy==1.19"
SCRIPT="test"
python: 3.5
python: 3.8
cache: False
-
env:
NUMPY="numpy==1.16"
SCRIPT="test"
python: 3.7
dist: xenial
python: 3.1
dist: focal
-
env:
SCRIPT="docs"
Expand Down
3 changes: 1 addition & 2 deletions pytest_allclose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Pytest fixture extending Numpy's allclose function.
"""

from .version import version as __version__

from .plugin import report_rmses
from .version import version as __version__

__copyright__ = "2019-2019 pytest_plt contributors"
__license__ = "MIT license"
20 changes: 9 additions & 11 deletions pytest_allclose/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def _allclose(
print_fail=5,
record_rmse=True,
):
"""Checks if two arrays are close, mimicking `numpy.allclose`.
"""
"""Checks if two arrays are close, mimicking `numpy.allclose`."""

if len(overrides) > 0:
override_args = overrides[min(call_count[0], len(overrides) - 1)]
Expand Down Expand Up @@ -117,11 +116,10 @@ def _allclose(
for k, ind in enumerate(zip(*(~close).nonzero())):
if k >= print_fail:
break
diffs.append("%s: %s %s" % (ind, broadcast_a[ind], broadcast_b[ind]))
diffs.append(f"{ind}: {broadcast_a[ind]} {broadcast_b[ind]}")

print(
"allclose first %d failures:\n %s" % (len(diffs), "\n ".join(diffs))
)
diff_str = "\n".join(diffs)
print(f"allclose first {len(diffs)} failures:\n {diff_str}")

return result

Expand All @@ -134,7 +132,7 @@ def _allclose(


def _rms(x, axis=None, keepdims=False):
return np.sqrt(np.mean(x ** 2, axis=axis, keepdims=keepdims))
return np.sqrt(np.mean(x**2, axis=axis, keepdims=keepdims))


def _safe_rms(x):
Expand Down Expand Up @@ -170,7 +168,7 @@ def _get_allclose_overrides(request):

k, v = entry.split("=")
if k not in _allclose_arg_types:
raise ValueError("Unrecognized argument %r" % k)
raise ValueError(f"Unrecognized argument '{k}'")

kwargs[k] = _allclose_arg_types[k](v)

Expand Down Expand Up @@ -222,8 +220,8 @@ def report_rmses(terminalreporter, relative=True):

if len(all_rmses) > 0:
relstr = "relative " if relative else ""
tr.write_sep("=", "%sroot mean squared error for allclose checks" % relstr)
tr.write_sep("=", f"{relstr}root mean squared error for allclose checks")
tr.write_line(
"mean %sRMSE: %.5f +/- %.4f (std)"
% (relstr, np.mean(all_rmses), np.std(all_rmses))
f"mean {relstr}RMSE: {np.mean(all_rmses):.5f} "
f"+/- {np.std(all_rmses):.4f} (std)"
)
27 changes: 10 additions & 17 deletions pytest_allclose/tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest


pytest_plugins = ["pytester"] # adds the `testdir` fixture


Expand All @@ -27,40 +26,36 @@ def assert_all_passed(result):
def test_rmse_output(offsets, relative, testdir):
testdir.makeconftest(
dedent(
"""\
f"""\
from pytest_allclose import report_rmses

def pytest_terminal_summary(terminalreporter):
report_rmses(terminalreporter, relative={relative})
""".format(
relative=relative
)
"""
)
)

testdir.makefile(
".py",
test_rmse_output=dedent(
"""\
f"""\
import numpy as np
import pytest

@pytest.mark.parametrize('offset', [{offsets}])
@pytest.mark.parametrize('offset', [{', '.join(str(x) for x in offsets)}])
def test_rmse(offset, allclose):
x = np.linspace(-1, 1)
y = x + offset
assert allclose(y, x, atol=offset + 1e-8)
""".format(
offsets=", ".join(str(x) for x in offsets)
)
"""
),
)

result = testdir.runpytest("-v")
n_passed = assert_all_passed(result)
assert n_passed > 0

tag = "mean %sRMSE: " % ("relative " if relative else "")
tag = f"mean {'relative ' if relative else ''}RMSE: "
lines = [s[len(tag) :] for s in result.outlines if s.startswith(tag)]
assert len(lines) == 1
line = lines[0]
Expand All @@ -69,7 +64,7 @@ def test_rmse(offset, allclose):
mean, std = float(parts[0]), float(parts[2])

x = np.linspace(-1, 1)
x_rms = np.sqrt(np.mean(x ** 2))
x_rms = np.sqrt(np.mean(x**2))
rmses = [offset / x_rms for offset in offsets] if relative else offsets
assert np.allclose(mean, np.mean(rmses), atol=1e-4)
assert np.allclose(std, np.std(rmses), atol=1e-4)
Expand All @@ -80,17 +75,15 @@ def test_print_fail_output(rel_error, print_fail, testdir):
testdir.makefile(
".py",
test_print_fail_output=dedent(
"""\
f"""\
import numpy as np

def test_print_fail(allclose):
t = np.linspace(0, 1)
x = np.sin(2*np.pi*t)
y = x * {rel_error}
assert allclose(y, x, atol=0.001, rtol=0, print_fail={print_fail:d})
""".format(
rel_error=rel_error, print_fail=print_fail
)
"""
),
)

Expand Down Expand Up @@ -159,4 +152,4 @@ def test_dummy(allclose):

result = testdir.runpytest("-v")
outcomes = result.parseoutcomes()
assert outcomes.get("passed", 0) == 0 and outcomes.get("error", 0) == 1
assert outcomes.get("passed", 0) == 0 and outcomes.get("errors", 0) == 1
24 changes: 16 additions & 8 deletions pytest_allclose/version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Automatically generated by nengo-bones, do not edit this file directly

# pylint: disable=consider-using-f-string

"""pytest-allclose version information.

We use semantic versioning (see http://semver.org/).
We use semantic versioning (see http://semver.org/)
and conform to PEP440 (see https://www.python.org/dev/peps/pep-0440/).
'.devN' will be added to the version unless the code base represents
'.dev0' will be added to the version unless the code base represents
a release version. Release versions are git tagged with the version.
"""

name = "pytest_allclose"
version_info = (1, 0, 1) # (major, minor, patch)
version_info = (1, 0, 1)

name = "pytest-allclose"
dev = 0

version = "{v}{dev}".format(
v=".".join(str(v) for v in version_info),
dev=(".dev%d" % dev) if dev is not None else "",
)
# use old string formatting, so that this can still run in Python <= 3.5
# (since this file is parsed in setup.py, before python_requires is applied)
version = ".".join(str(v) for v in version_info)
if dev is not None:
version += ".dev%d" % dev

copyright = "Copyright (c) 2019-2022 Applied Brain Research"
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def read(*filenames, **kwargs):
version = runpy.run_path(str(root / "pytest_allclose" / "version.py"))["version"]

install_req = [
"numpy>=1.11",
"numpy>=1.19",
"pytest",
]
docs_req = [
Expand Down Expand Up @@ -67,7 +67,7 @@ def read(*filenames, **kwargs):
"optional": optional_req,
"tests": tests_req,
},
python_requires=">=3.5",
python_requires=">=3.6",
entry_points={
"pytest11": [
"allclose = pytest_allclose.plugin",
Expand All @@ -78,8 +78,10 @@ def read(*filenames, **kwargs):
"Framework :: Pytest",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)