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"}
|
||||
|
||||
Reference in New Issue
Block a user