[case testTrioBasic]
import trio
import trio.testing
from typing import List, Sequence

async def sleep_sort(values: Sequence[float]) -> List[float]:
    result = []  # type: List[float]

    async def worker(value: float) -> None:
        await trio.sleep(value)
        result.append(value)

    async with trio.open_nursery() as nursery:
        reveal_type(nursery)  # N: Revealed type is "trio.Nursery"
        reveal_type(nursery.cancel_scope)  # N: Revealed type is "trio.CancelScope"
        for value in values:
            nursery.start_soon(worker, value)
            nursery.start_soon(worker)  # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[], Awaitable[Any]]"
            nursery.start_soon(worker, "hi")  # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[str], Awaitable[Any]]"
            nursery.start_soon(worker, value, value)  # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[float, float], Awaitable[Any]]"

    return result

val = trio.run(sleep_sort, (1, 3, 5, 2, 4), clock=trio.testing.MockClock(autojump_threshold=0))
reveal_type(val)  # N: Revealed type is "builtins.list[builtins.float]"
trio.run(sleep_sort, ["hi", "there"])  # E: Argument 1 to "run" has incompatible type "Callable[[Sequence[float]], Coroutine[Any, Any, List[float]]]"; expected "Callable[[List[str]], Awaitable[List[float]]]"


reveal_type(trio.Event().statistics().tasks_waiting)  # N: Revealed type is "builtins.int"

[case testTrioBasic_NoPlugin]
import trio
import trio.testing
from typing import List, Sequence

async def sleep_sort(values: Sequence[float]) -> List[float]:
    result = []  # type: List[float]

    async def worker(value: float) -> None:
        await trio.sleep(value)
        result.append(value)

    async with trio.open_nursery() as nursery:
        reveal_type(nursery)  # N: Revealed type is "trio.Nursery"
        reveal_type(nursery.cancel_scope)  # N: Revealed type is "trio.CancelScope"
        for value in values:
            nursery.start_soon(worker, value)
            nursery.start_soon(worker)
            nursery.start_soon(worker, "hi")
            nursery.start_soon(worker, value, value)

    return result

val = trio.run(sleep_sort, (1, 3, 5, 2, 4), clock=trio.testing.MockClock(autojump_threshold=0))
reveal_type(val)  # N: Revealed type is "builtins.list[builtins.float]"
trio.run(sleep_sort, ["hi", "there"])

reveal_type(trio.Event().statistics().tasks_waiting)  # N: Revealed type is "builtins.int"

[case testExceptions]
import trio

raise trio.Cancelled()  # E: Cannot instantiate abstract class "Cancelled" with abstract attribute "_objects_of_this_type_are_not_directly_constructible"

try:
    trio.run(trio.sleep, 3)
except trio.Cancelled:
    raise

def filter_exc(exc: BaseException):
    if isinstance(exc, trio.BrokenResourceError):
        return None
    return exc

with trio.MultiError.catch(filter_exc):
    pass

[case testOverloaded]
from typing import overload, Any

@overload
async def fn(arg: int) -> str: ...
@overload
async def fn(arg: float) -> bytes: ...
async def fn(arg: Any) -> Any:
    return arg

import trio
reveal_type(trio.run(fn, 3))  # N: Revealed type is "builtins.str"
reveal_type(trio.run(fn, 3.4))  # N: Revealed type is "builtins.bytes"
trio.run(fn)  # E: Argument 1 to "run" has incompatible type overloaded function; expected "Callable[[], Awaitable[str]]"

[case testChannels]
from typing import Tuple
import trio
send, receive = trio.open_memory_channel[Tuple[int, str]](5)
reveal_type(send)  # N: Revealed type is "trio.MemorySendChannel[Tuple[builtins.int, builtins.str]]"
reveal_type(receive)  # N: Revealed type is "trio.MemoryReceiveChannel[Tuple[builtins.int, builtins.str]]"
async def test() -> None:
    await send.send((5, "hi"))
    reveal_type(receive.receive_nowait()[1])  # N: Revealed type is "builtins.str"

[case testSubprocessPaths]
import trio
from pathlib import Path
async def test() -> None:
    await trio.run_process(["cat", Path("/dev/null"), b"/dev/null"])
    await trio.run_process(["cat", Path("/dev/null")], cwd=Path("/"))
    await trio.run_process("cat /dev/null", shell=True)

[case testOptionalCwd]
import trio
async def test(_cwd=None) -> None:
    await trio.run_process(["cat", "dev/null"], cwd="/")
    await trio.run_process(["cat", "/dev/null"], cwd=_cwd)
