Skip to content

Commit

Permalink
cover assertion about generic
Browse files Browse the repository at this point in the history
This commit was sponsored by Jason Walker, Devin Prater, Jason Mills,
and my other patrons.  If you want to join them, you can support my
work at https://glyph.im/patrons/.
  • Loading branch information
glyph committed Aug 15, 2024
1 parent 7a99438 commit a43b3df
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion automat/_test/test_type_based.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Callable, List, Protocol, TypeVar
from typing import Callable, Generic, List, Protocol, TypeVar
from unittest import TestCase

from .. import AlreadyBuiltError, NoTransition, TypeMachineBuilder, pep614

T = TypeVar("T")


class TestProtocol(Protocol):

Expand All @@ -18,6 +20,7 @@ def value(self) -> int:

class ArgTaker(Protocol):
def takeSomeArgs(self, arg1: int = 0, arg2: str = "") -> None: ...
def value(self) -> int: ...


class NoOpCore:
Expand Down Expand Up @@ -416,6 +419,31 @@ def threevalue(proto: TestProtocol, core: NoOpCore, three: Three) -> int:
7,
)

def test_genericData(self) -> None:
builder = TypeMachineBuilder(ArgTaker, NoOpCore)
one = builder.state("one")

@dataclass
class Gen(Generic[T]):
t: T

def dat(
proto: ArgTaker, core: NoOpCore, arg1: int = 0, arg2: str = ""
) -> Gen[int]:
return Gen(arg1)

two = builder.state("two", dat)
one.upon(ArgTaker.takeSomeArgs).to(two).returns(None)

@pep614(two.upon(ArgTaker.value).loop())
def val(proto: ArgTaker, core: NoOpCore, data: Gen[int]) -> int:
return data.t

b = builder.build()
m = b(NoOpCore())
m.takeSomeArgs(3)
self.assertEqual(m.value(), 3)

def test_noMethodsInAltStateDataFactory(self) -> None:
"""
When the state machine is received by a data factory during
Expand Down

0 comments on commit a43b3df

Please sign in to comment.