Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsokl committed Oct 25, 2023
1 parent 3ca1f17 commit 1cf9033
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_zen_exclude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from hydra_zen import builds, instantiate, make_custom_builds_fn


@pytest.mark.parametrize("bad_exclude", [1, "x"])
def test_validate_exclude(bad_exclude):
with pytest.raises(TypeError):
builds(dict, zen_exclude=bad_exclude)


def foo(x=1, _y=2, _z=3):
return "apple"


@pytest.mark.parametrize("partial", [True, False])
@pytest.mark.parametrize("custom_builds", [True, False])
@pytest.mark.parametrize("exclude", [["_y", "_z"], lambda x: x.startswith("_")])
def test_exclude_named(partial: bool, custom_builds: bool, exclude):
if custom_builds:
b = make_custom_builds_fn(
populate_full_signature=True, zen_partial=partial, zen_exclude=exclude
)
conf = b(foo)()
else:
conf = builds(
foo, populate_full_signature=True, zen_partial=partial, zen_exclude=exclude
)()
assert not hasattr(conf, "_y")
assert not hasattr(conf, "_z")
assert conf.x == 1
if not partial:
assert instantiate(conf) == "apple"
else:
assert instantiate(conf)() == "apple" # type: ignore

0 comments on commit 1cf9033

Please sign in to comment.