Update tests to make beartype optional

This commit is contained in:
Patrick Kidger
2022-07-11 19:27:16 +01:00
parent 35201eb189
commit 81238e38e8
3 changed files with 27 additions and 11 deletions
+9 -5
View File
@@ -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
View File
@@ -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
+10 -3
View File
@@ -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():