Skip to content

Commit

Permalink
test: add some tests for issue #64
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseylin committed Aug 28, 2023
1 parent b5789f9 commit fbb7618
Showing 1 changed file with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)
from auto_disc.auto_disc.utils.expose_config.expose_config import expose_config


class TestPublicExposeConfig:
def test_key_collision(self):
with pytest.raises(ValueError):
Expand Down Expand Up @@ -360,3 +359,54 @@ def __init__(self, **params):
assert System(**p_dict).SY == 256
assert System(**p_dict).version == "fft"
assert System(**p_dict).scalar == 1.0


class TestMultipleClasses:
def test_basic(self):
@dataclass
class SystemParams(Defaults):
version: str = defaults("fft", domain=["fft", "conv"])

@SystemParams.expose_config()
class System:
def __init__(self, version: str):
self.version = version

@dataclass
class OtherParams(Defaults):
other_version: str = defaults("fft", domain=["fft", "conv"])

@OtherParams.expose_config()
class OtherSystem:
def __init__(self, other_version: str):
self.other_version = other_version

assert OtherSystem.CONFIG_DEFINITION != System.CONFIG_DEFINITION
assert OtherSystem.CONFIG_DEFINITION["other_version"] is not None
assert System.CONFIG_DEFINITION["version"] is not None

def test_inheritance(self):
class Base:
CONFIG_DEFINITION = {}

@dataclass
class SystemParams(Defaults):
version: str = defaults("fft", domain=["fft", "conv"])

@SystemParams.expose_config()
class System(Base):
def __init__(self, version: str):
self.version = version

@dataclass
class OtherParams(Defaults):
other_version: str = defaults("fft", domain=["fft", "conv"])

@OtherParams.expose_config()
class OtherSystem(Base):
def __init__(self, other_version: str):
self.other_version = other_version

assert OtherSystem.CONFIG_DEFINITION != System.CONFIG_DEFINITION
assert OtherSystem.CONFIG_DEFINITION["other_version"] is not None
assert System.CONFIG_DEFINITION["version"] is not None

0 comments on commit fbb7618

Please sign in to comment.