fix test interfaces not being disabled

This commit is contained in:
sneakers-the-rat 2024-09-03 13:10:26 -07:00
parent 4152af1f91
commit 88fd42cdc3
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
2 changed files with 26 additions and 12 deletions

View file

@ -1,5 +1,11 @@
import pytest """
Tests for the interface base model,
for tests that should apply to all interfaces, use ``test_interfaces.py``
"""
import gc
import pytest
import numpy as np import numpy as np
from numpydantic.interface import Interface from numpydantic.interface import Interface
@ -8,6 +14,7 @@ from numpydantic.interface import Interface
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def interfaces(): def interfaces():
"""Define test interfaces in this module, and delete afterwards""" """Define test interfaces in this module, and delete afterwards"""
interfaces_enabled = True
class Interface1(Interface): class Interface1(Interface):
input_types = (list,) input_types = (list,)
@ -24,7 +31,7 @@ def interfaces():
@classmethod @classmethod
def enabled(cls) -> bool: def enabled(cls) -> bool:
return True return interfaces_enabled
Interface2 = type("Interface2", Interface1.__bases__, dict(Interface1.__dict__)) Interface2 = type("Interface2", Interface1.__bases__, dict(Interface1.__dict__))
Interface2.checked = False Interface2.checked = False
@ -44,7 +51,7 @@ def interfaces():
@classmethod @classmethod
def enabled(cls) -> bool: def enabled(cls) -> bool:
return True return interfaces_enabled
class Interfaces: class Interfaces:
interface1 = Interface1 interface1 = Interface1
@ -55,9 +62,13 @@ def interfaces():
yield Interfaces yield Interfaces
# Interface.__subclasses__().remove(Interface1) # Interface.__subclasses__().remove(Interface1)
# Interface.__subclasses__().remove(Interface2) # Interface.__subclasses__().remove(Interface2)
del Interfaces
del Interface1 del Interface1
del Interface2 del Interface2
del Interface3 del Interface3
del Interface4
interfaces_enabled = False
gc.collect()
def test_interface_match_error(interfaces): def test_interface_match_error(interfaces):
@ -151,12 +162,3 @@ def test_interface_recursive(interfaces):
assert issubclass(interfaces.interface3, interfaces.interface1) assert issubclass(interfaces.interface3, interfaces.interface1)
assert issubclass(interfaces.interface1, Interface) assert issubclass(interfaces.interface1, Interface)
assert interfaces.interface4 in ifaces assert interfaces.interface4 in ifaces
def test_interface_revalidate(all_interfaces):
"""
An interface should revalidate with the output of its initial validation
See: https://github.com/p2p-ld/numpydantic/pull/14
"""
_ = type(all_interfaces)(array=all_interfaces.array)

View file

@ -0,0 +1,12 @@
"""
Tests that should be applied to all interfaces
"""
def test_interface_revalidate(all_interfaces):
"""
An interface should revalidate with the output of its initial validation
See: https://github.com/p2p-ld/numpydantic/pull/14
"""
_ = type(all_interfaces)(array=all_interfaces.array)