Skip to content

Commit

Permalink
fix: typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Sep 15, 2024
1 parent 8b34941 commit f8da4c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion moccasin/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pytest
import sys
from argparse import Namespace
from _pytest.config import get_config as get_pytest_config

from moccasin.constants.vars import TESTS_FOLDER

Expand Down
26 changes: 16 additions & 10 deletions moccasin/fixture_tools.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
from types import ModuleType
from typing import Callable
import pytest
from typing import Callable, Literal, cast
from pytest import fixture
from moccasin.config import get_config
from boa.contracts.vyper.vyper_contract import VyperContract
from boa.contracts.abi.abi_contract import ABIContract
import inspect


ScopeType = Literal["function", "class", "module", "package", "session"]


def request_fixtures(
fixture_requests: list[str | tuple[str, str]], scope: str = "module"
):
# Dear Charles, don't kill me. Idk how this works.
caller_frame = inspect.currentframe().f_back
current_frame = inspect.currentframe()
if current_frame is None or current_frame.f_back is None:
raise RuntimeError("Cannot determine caller module")
caller_frame = current_frame.f_back

caller_module = inspect.getmodule(caller_frame)
if caller_module is None:
raise RuntimeError("Cannot determine caller module")
Expand Down Expand Up @@ -46,20 +53,19 @@ def deploy_func() -> VyperContract | ABIContract:
return active_network.get_or_deploy_contract(named_contract_name)

# Create the fixture function
fixture = make_fixture(deploy_func, fixture_name, scope)
fixture_function = make_fixture(deploy_func, fixture_name, cast(ScopeType, scope))

# Add the fixture to the module's namespace
setattr(module, fixture_name, fixture)
setattr(module, fixture_name, fixture_function)


def make_fixture(
deploy_func: Callable[[], VyperContract | ABIContract],
fixture_name: str,
scope: str,
scope: Literal["function", "class", "module", "package", "session"],
) -> Callable[[], VyperContract | ABIContract]:
@pytest.fixture(scope=scope)
def fixture(deploy_func=deploy_func):
@fixture(scope=scope, name=fixture_name)
def fixture_func(deploy_func=deploy_func):
return deploy_func()

fixture.__name__ = fixture_name
return fixture
return cast(Callable[[], VyperContract | ABIContract], fixture_func)

0 comments on commit f8da4c4

Please sign in to comment.