Merge pull request #3 from google/test-tidy

Test tidy
This commit is contained in:
Patrick Kidger
2022-07-12 10:11:50 +01:00
committed by GitHub
9 changed files with 26 additions and 16 deletions
View File
+5 -1
View File
@@ -27,7 +27,11 @@ import typeguard
try: try:
import beartype import beartype
except ImportError: except ImportError:
typecheck_params = [typeguard.typechecked]
def skip(*args, **kwargs):
pytest.skip("Beartype not installed")
typecheck_params = [typeguard.typechecked, skip]
else: else:
typecheck_params = [typeguard.typechecked, beartype.beartype] typecheck_params = [typeguard.typechecked, beartype.beartype]
+2 -1
View File
@@ -19,10 +19,11 @@
import jax.numpy as jnp import jax.numpy as jnp
import pytest import pytest
from helpers import ParamError
from jaxtyping import f32 from jaxtyping import f32
from .helpers import ParamError
def g(x: f32[" b"]): def g(x: f32[" b"]):
pass pass
+2 -1
View File
@@ -19,10 +19,11 @@
import jax.numpy as jnp import jax.numpy as jnp
import pytest import pytest
from helpers import ParamError
from jaxtyping import f32 from jaxtyping import f32
from .helpers import ParamError
def g(x: f32[" b"]): def g(x: f32[" b"]):
pass pass
@@ -19,10 +19,11 @@
import jax.numpy as jnp import jax.numpy as jnp
import pytest import pytest
from helpers import ParamError
from jaxtyping import f32 from jaxtyping import f32
from ..helpers import ParamError
def g(x: f32[" b"]): def g(x: f32[" b"]):
pass pass
+2 -1
View File
@@ -19,10 +19,11 @@
import jax.numpy as jnp import jax.numpy as jnp
import pytest import pytest
from helpers import ParamError
from jaxtyping import f32 from jaxtyping import f32
from .helpers import ParamError
def g(x: f32[" b"]): def g(x: f32[" b"]):
pass pass
+2 -1
View File
@@ -20,10 +20,11 @@
import jax.numpy as jnp import jax.numpy as jnp
import jax.random as jr import jax.random as jr
import pytest import pytest
from helpers import ParamError, ReturnError
from jaxtyping import Array, f, f32, jaxtyped from jaxtyping import Array, f, f32, jaxtyped
from .helpers import ParamError, ReturnError
def test_basic(typecheck): def test_basic(typecheck):
@jaxtyped @jaxtyped
+9 -9
View File
@@ -24,9 +24,9 @@ from jaxtyping import install_import_hook
def test_import_hook_typeguard(): def test_import_hook_typeguard():
hook = install_import_hook( 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() hook.uninstall()
@@ -35,29 +35,29 @@ def test_import_hook_beartype():
try: try:
import beartype # noqa: F401 import beartype # noqa: F401
except ImportError: except ImportError:
pass pytest.skip("Beartype not installed")
else: else:
hook = install_import_hook( 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() hook.uninstall()
def test_import_hook_transitive(): def test_import_hook_transitive():
hook = install_import_hook( 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() hook.uninstall()
def test_import_hook_broken_checker(): def test_import_hook_broken_checker():
hook = install_import_hook( 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): with pytest.raises(AttributeError):
import import_hook_tester_broken_checker # noqa: F401 from . import import_hook_tester_broken_checker # noqa: F401
hook.uninstall() hook.uninstall()
+2 -1
View File
@@ -24,10 +24,11 @@ import jax
import jax.numpy as jnp import jax.numpy as jnp
import jax.random as jr import jax.random as jr
import pytest import pytest
from helpers import make_mlp, ParamError
from jaxtyping import f, jaxtyped, PyTree from jaxtyping import f, jaxtyped, PyTree
from .helpers import make_mlp, ParamError
def test_direct(typecheck): def test_direct(typecheck):
@typecheck @typecheck