File: test_combomethod.py

package info (click to toggle)
python-eth-utils 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,140 kB
  • sloc: python: 5,985; makefile: 238
file content (32 lines) | stat: -rw-r--r-- 666 bytes parent folder | download
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"