Skip to content

Commit

Permalink
Unittesting Node and LeafNode
Browse files Browse the repository at this point in the history
  • Loading branch information
rayk committed Nov 10, 2023
1 parent fb2b3ad commit 1e7ba5f
Show file tree
Hide file tree
Showing 3 changed files with 581 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/labone/nodetree/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def path_segments_to_node(
if unique_value in self._cache_path_segments_to_node:
return self._cache_path_segments_to_node[unique_value]

result = Node.build(self, path_segments)
result = Node.build(tree_manager=self, path_segments=path_segments)
self._cache_path_segments_to_node[unique_value] = result
return result

Expand Down Expand Up @@ -996,6 +996,7 @@ async def _set(
@classmethod
def build(
cls,
*,
tree_manager: NodeTreeManager,
path_segments: tuple[NormalizedPathSegment, ...],
path_aliases: dict[
Expand Down
87 changes: 84 additions & 3 deletions tests/nodetree/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@
from unittest.mock import MagicMock

import pytest
from labone.nodetree.helper import join_path, paths_to_nested_dict
from labone.nodetree.node import MetaNode, NodeTreeManager, ResultNode

if t.TYPE_CHECKING:
from labone.core.subscription import DataQueue
from labone.nodetree.enum import NodeEnum
from labone.nodetree.helper import (
NormalizedPathSegment,
join_path,
paths_to_nested_dict,
)
from labone.nodetree.node import (
LeafNode,
MetaNode,
NodeTreeManager,
PartialNode,
ResultNode,
WildcardNode,
)

if t.TYPE_CHECKING:
from src.labone.core.value import AnnotatedValue
from src.labone.nodetree.node import Node
from src.labone.nodetree.node import Node
from tests.nodetree.zi_responses import zi_get_responses


Expand Down Expand Up @@ -199,3 +214,69 @@ def __init__(self, path_segments):
value_structure=None,
timestamp=None,
)


class MockNode(Node):
"""Get simple Node like object by path"""

def __init__(self, path_segments):
super().__init__(
path_segments=path_segments,
tree_manager=None,
subtree_paths=None,
path_aliases=None,
)

def _get(self, *_, **__):
return

def _set(self, *_, **__):
return

def subscribe(self) -> DataQueue:
return

def try_generate_subnode(
self,
next_path_segment: NormalizedPathSegment, # noqa: ARG002
) -> Node:
return

def wait_for_state_change(
self,
value: int | NodeEnum, # noqa: ARG002
*,
invert: bool = False, # noqa: ARG002
timeout: float = 2, # noqa: ARG002
) -> None:
return


class MockPartialNode(PartialNode):
def __init__(self, path_segments):
super().__init__(
tree_manager=None,
path_segments=path_segments,
subtree_paths=None,
path_aliases=None,
)


class MockLeafNode(LeafNode):
def __init__(self, path_segments):
super().__init__(
tree_manager=None,
path_segments=path_segments,
subtree_paths=None,
path_aliases=None,
)


class MockWildcardNode(WildcardNode):
def __init__(self, path_segments):
super().__init__(
tree_manager=None,
path_segments=path_segments,
subtree_paths=None,
path_aliases=None,
)
Loading

0 comments on commit 1e7ba5f

Please sign in to comment.