-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add "zntrack.apply" * rename class name * update docstrings * fix eager
- Loading branch information
Showing
7 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Test the apply function.""" | ||
|
||
import pytest | ||
|
||
import zntrack.examples | ||
|
||
|
||
@pytest.mark.parametrize("eager", [True, False]) | ||
def test_apply(proj_path, eager) -> None: | ||
"""Test the "zntrack.apply" function.""" | ||
project = zntrack.Project() | ||
|
||
JoinedParamsToOuts = zntrack.apply(zntrack.examples.ParamsToOuts, "join") | ||
|
||
with project: | ||
a = zntrack.examples.ParamsToOuts(params=["a", "b"]) | ||
b = JoinedParamsToOuts(params=["a", "b"]) | ||
c = zntrack.apply(zntrack.examples.ParamsToOuts, "join")(params=["a", "b", "c"]) | ||
|
||
project.run(eager=eager) | ||
|
||
a.load() | ||
b.load() | ||
c.load() | ||
|
||
assert a.outs == ["a", "b"] | ||
assert b.outs == "a-b" | ||
assert c.outs == "a-b-c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Zntrack apply module for custom "run" methods.""" | ||
|
||
import typing as t | ||
|
||
o = t.TypeVar("o") | ||
|
||
|
||
def apply(obj: o, method: str) -> o: | ||
"""Return a new object like "o" which has the method string attached.""" | ||
|
||
class MockInheritanceClass(obj): | ||
"""Copy of the original class with the new method attribute. | ||
We can not set the method directly on the original class, because | ||
it would be used by all the other instances of the class as well. | ||
""" | ||
|
||
_method = method | ||
|
||
MockInheritanceClass.__module__ = obj.__module__ | ||
MockInheritanceClass.__name__ = obj.__name__ | ||
|
||
return MockInheritanceClass |