mirror of
https://github.com/wassname/jaxtyping.git
synced 2026-09-09 11:24:55 +08:00
Update tests to make beartype optional
This commit is contained in:
+9
-5
@@ -19,13 +19,20 @@
|
||||
|
||||
import random
|
||||
|
||||
import beartype
|
||||
import jax.random as jr
|
||||
import pytest
|
||||
import typeguard
|
||||
|
||||
|
||||
@pytest.fixture(params=[typeguard.typechecked, beartype.beartype])
|
||||
try:
|
||||
import beartype
|
||||
except ImportError:
|
||||
typecheck_params = [typeguard.typechecked]
|
||||
else:
|
||||
typecheck_params = [typeguard.typechecked, beartype.beartype]
|
||||
|
||||
|
||||
@pytest.fixture(params=typecheck_params)
|
||||
def typecheck(request):
|
||||
return request.param
|
||||
|
||||
@@ -37,6 +44,3 @@ def getkey():
|
||||
return jr.PRNGKey(random.randint(0, 2**31 - 1))
|
||||
|
||||
return _getkey
|
||||
|
||||
|
||||
ParamException = (TypeError, beartype.roar.BeartypeCallHintParamViolation)
|
||||
|
||||
+8
-3
@@ -17,12 +17,17 @@
|
||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import beartype
|
||||
import equinox as eqx
|
||||
|
||||
|
||||
ParamError = (TypeError, beartype.roar.BeartypeCallHintParamViolation)
|
||||
ReturnError = (TypeError, beartype.roar.BeartypeCallHintReturnViolation)
|
||||
try:
|
||||
import beartype
|
||||
except ImportError:
|
||||
ParamError = TypeError
|
||||
ReturnError = TypeError
|
||||
else:
|
||||
ParamError = (TypeError, beartype.roar.BeartypeCallHintParamViolation)
|
||||
ReturnError = (TypeError, beartype.roar.BeartypeCallHintReturnViolation)
|
||||
|
||||
|
||||
@eqx.filter_jit
|
||||
|
||||
@@ -32,10 +32,17 @@ def test_import_hook_typeguard():
|
||||
|
||||
|
||||
def test_import_hook_beartype():
|
||||
hook = install_import_hook("import_hook_tester_beartype", ("beartype", "beartype"))
|
||||
import import_hook_tester_beartype # noqa: F401
|
||||
try:
|
||||
import beartype # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
hook = install_import_hook(
|
||||
"import_hook_tester_beartype", ("beartype", "beartype")
|
||||
)
|
||||
import import_hook_tester_beartype # noqa: F401
|
||||
|
||||
hook.uninstall()
|
||||
hook.uninstall()
|
||||
|
||||
|
||||
def test_import_hook_transitive():
|
||||
|
||||
Reference in New Issue
Block a user