Skip to content

Commit

Permalink
test __post_init__ (#114)
Browse files Browse the repository at this point in the history
* test `__post_init__`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* replace with typing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored Oct 17, 2024
1 parent 558eef4 commit 48636f4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_post_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import dataclasses
import znflow
import typing as t


@dataclasses.dataclass
class NodeWithPostInit(znflow.Node):
input: int
output: t.Optional[int] = None

def __post_init__(self):
self.input = self.input * 2

def run(self):
self.output = self.input + 1


def test_post_init():
graph = znflow.DiGraph()

with graph:
node = NodeWithPostInit(input=10)

assert node.input == 20

graph.run()

assert node.output == 21
assert node.input == 20

0 comments on commit 48636f4

Please sign in to comment.