From 9f75958b2d8945245fd57388b4a02b6a9b038cd8 Mon Sep 17 00:00:00 2001 From: Patrick Kidger <33688385+patrick-kidger@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:03:19 +0100 Subject: [PATCH 1/2] Make test/helpers.py a relative import --- test/__init__.py | 0 test/import_hook_tester_beartype.py | 3 ++- test/import_hook_tester_broken_checker.py | 3 ++- .../another_file.py | 3 ++- test/import_hook_tester_typeguard.py | 3 ++- test/test_array.py | 3 ++- test/test_import_hook.py | 16 ++++++++-------- test/test_pytree.py | 3 ++- 8 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 test/__init__.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/import_hook_tester_beartype.py b/test/import_hook_tester_beartype.py index 6c5d01d..6e69d53 100644 --- a/test/import_hook_tester_beartype.py +++ b/test/import_hook_tester_beartype.py @@ -19,10 +19,11 @@ import jax.numpy as jnp import pytest -from helpers import ParamError from jaxtyping import f32 +from .helpers import ParamError + def g(x: f32[" b"]): pass diff --git a/test/import_hook_tester_broken_checker.py b/test/import_hook_tester_broken_checker.py index 6c5d01d..6e69d53 100644 --- a/test/import_hook_tester_broken_checker.py +++ b/test/import_hook_tester_broken_checker.py @@ -19,10 +19,11 @@ import jax.numpy as jnp import pytest -from helpers import ParamError from jaxtyping import f32 +from .helpers import ParamError + def g(x: f32[" b"]): pass diff --git a/test/import_hook_tester_transitive/another_file.py b/test/import_hook_tester_transitive/another_file.py index 6c5d01d..b7c9a9b 100644 --- a/test/import_hook_tester_transitive/another_file.py +++ b/test/import_hook_tester_transitive/another_file.py @@ -19,10 +19,11 @@ import jax.numpy as jnp import pytest -from helpers import ParamError from jaxtyping import f32 +from ..helpers import ParamError + def g(x: f32[" b"]): pass diff --git a/test/import_hook_tester_typeguard.py b/test/import_hook_tester_typeguard.py index 6c5d01d..6e69d53 100644 --- a/test/import_hook_tester_typeguard.py +++ b/test/import_hook_tester_typeguard.py @@ -19,10 +19,11 @@ import jax.numpy as jnp import pytest -from helpers import ParamError from jaxtyping import f32 +from .helpers import ParamError + def g(x: f32[" b"]): pass diff --git a/test/test_array.py b/test/test_array.py index 96fdb9b..e6de38b 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -20,10 +20,11 @@ import jax.numpy as jnp import jax.random as jr import pytest -from helpers import ParamError, ReturnError from jaxtyping import Array, f, f32, jaxtyped +from .helpers import ParamError, ReturnError + def test_basic(typecheck): @jaxtyped diff --git a/test/test_import_hook.py b/test/test_import_hook.py index 8f81762..ddde0e4 100644 --- a/test/test_import_hook.py +++ b/test/test_import_hook.py @@ -24,9 +24,9 @@ from jaxtyping import install_import_hook def test_import_hook_typeguard(): hook = install_import_hook( - "import_hook_tester_typeguard", ("typeguard", "typechecked") + "test.import_hook_tester_typeguard", ("typeguard", "typechecked") ) - import import_hook_tester_typeguard # noqa: F401 + from . import import_hook_tester_typeguard # noqa: F401 hook.uninstall() @@ -38,26 +38,26 @@ def test_import_hook_beartype(): pass else: hook = install_import_hook( - "import_hook_tester_beartype", ("beartype", "beartype") + "test.import_hook_tester_beartype", ("beartype", "beartype") ) - import import_hook_tester_beartype # noqa: F401 + from . import import_hook_tester_beartype # noqa: F401 hook.uninstall() def test_import_hook_transitive(): hook = install_import_hook( - "import_hook_tester_transitive", ("typeguard", "typechecked") + "test.import_hook_tester_transitive", ("typeguard", "typechecked") ) - import import_hook_tester_transitive # noqa: F401 + from . import import_hook_tester_transitive # noqa: F401 hook.uninstall() def test_import_hook_broken_checker(): hook = install_import_hook( - "import_hook_tester_broken_checker", ("jaxtyping", "does_not_exist") + "test.import_hook_tester_broken_checker", ("jaxtyping", "does_not_exist") ) with pytest.raises(AttributeError): - import import_hook_tester_broken_checker # noqa: F401 + from . import import_hook_tester_broken_checker # noqa: F401 hook.uninstall() diff --git a/test/test_pytree.py b/test/test_pytree.py index f549cb4..2bcbd7c 100644 --- a/test/test_pytree.py +++ b/test/test_pytree.py @@ -24,10 +24,11 @@ import jax import jax.numpy as jnp import jax.random as jr import pytest -from helpers import make_mlp, ParamError from jaxtyping import f, jaxtyped, PyTree +from .helpers import make_mlp, ParamError + def test_direct(typecheck): @typecheck From e162e1281abd02c77e41b82a07561447e1f6cd87 Mon Sep 17 00:00:00 2001 From: Patrick Kidger <33688385+patrick-kidger@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:07:42 +0100 Subject: [PATCH 2/2] Made missing beartype result in test skips rather than tests not running --- test/conftest.py | 6 +++++- test/test_import_hook.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index b3264ea..c69a0e3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -27,7 +27,11 @@ import typeguard try: import beartype except ImportError: - typecheck_params = [typeguard.typechecked] + + def skip(*args, **kwargs): + pytest.skip("Beartype not installed") + + typecheck_params = [typeguard.typechecked, skip] else: typecheck_params = [typeguard.typechecked, beartype.beartype] diff --git a/test/test_import_hook.py b/test/test_import_hook.py index ddde0e4..9077082 100644 --- a/test/test_import_hook.py +++ b/test/test_import_hook.py @@ -35,7 +35,7 @@ def test_import_hook_beartype(): try: import beartype # noqa: F401 except ImportError: - pass + pytest.skip("Beartype not installed") else: hook = install_import_hook( "test.import_hook_tester_beartype", ("beartype", "beartype")