type modernization
This commit is contained in:
@@ -3,11 +3,17 @@ from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
from daglib.dag import DAG
|
||||
from daglib.operations import all_nodes, transitive_closure
|
||||
from daglib.typing import DAGType, dictset
|
||||
|
||||
|
||||
class TestDAGInit:
|
||||
"""Test DAG initialization."""
|
||||
|
||||
def test_generic_alias_parameters(self) -> None:
|
||||
assert len(dictset.__type_params__) == 1
|
||||
assert len(DAGType.__type_params__) == 1
|
||||
|
||||
def test_init_empty(self) -> None:
|
||||
g = DAG()
|
||||
assert len(g) == 0
|
||||
@@ -281,6 +287,20 @@ class TestDAGCallbacks:
|
||||
class TestDAGComplexScenarios:
|
||||
"""Test complex usage patterns."""
|
||||
|
||||
def test_typed_traversal_and_subclass_returns(self) -> None:
|
||||
class IntDAG(DAG[int]):
|
||||
pass
|
||||
|
||||
graph = IntDAG()
|
||||
graph.add_edge(1, 2)
|
||||
graph.add_edge(2, 3)
|
||||
assert all_nodes(graph) == {1, 2, 3}
|
||||
assert transitive_closure(graph, 1) == {1, 2, 3}
|
||||
assert isinstance(graph.reverse, IntDAG)
|
||||
assert isinstance(graph.subgraph(1), IntDAG)
|
||||
graph.remove_edge(1, 2)
|
||||
assert 2 not in graph[1]
|
||||
|
||||
def test_chain_graph(self) -> None:
|
||||
g = DAG[str]()
|
||||
g["foo"] = {"bar"}
|
||||
|
||||
@@ -39,6 +39,10 @@ class TestDAGSetInit:
|
||||
s = DAGSetView(None)
|
||||
assert len(s) == 0
|
||||
|
||||
def test_from_scalar(self) -> None:
|
||||
s = DAGSetView[int](2)
|
||||
assert set(s) == {2}
|
||||
|
||||
|
||||
class TestDAGSetBasicOps:
|
||||
"""Test basic set operations."""
|
||||
@@ -169,6 +173,20 @@ class TestDAGSetCallbacks:
|
||||
class TestDAGSetInPlaceOperators:
|
||||
"""Test in-place set operators."""
|
||||
|
||||
def test_scalar_operators_preserve_instance(self) -> None:
|
||||
class IntSetView(DAGSetView[int]):
|
||||
pass
|
||||
|
||||
view = IntSetView({1, 2})
|
||||
original = view
|
||||
view += 3
|
||||
view |= 4
|
||||
view -= 1
|
||||
view &= 2
|
||||
view ^= 5
|
||||
assert view is original
|
||||
assert set(view) == {2, 5}
|
||||
|
||||
class TestIOR:
|
||||
def test_set(self) -> None:
|
||||
s = DAGSetView({"foo", 2})
|
||||
|
||||
Reference in New Issue
Block a user