1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import pytest
from eth_utils import (
combomethod,
)
@pytest.fixture()
def Getter():
class _Getter:
val = 1
@combomethod
def get(combo):
if isinstance(combo, type):
return f"{combo.val} by class"
elif isinstance(combo, _Getter):
return f"{combo.val} by instance"
else:
raise TypeError("Unreachable, unless you really monkey around")
return _Getter
def test_class_access(Getter):
assert Getter.get() == "1 by class"
def test_instance_access(Getter):
getter = Getter()
getter.val = 2
assert getter.get() == "2 by instance"
|