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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Phil Thompson <phil@riverbankcomputing.com>
import pytest
@pytest.fixture
def klass(module):
""" This is a fixture that returns an instance of Klass. """
return module.Klass()
def test_class_callables(module):
assert module.Klass.get_s_attr_int() == 0
module.Klass.set_s_attr_int(10)
assert module.Klass.get_s_attr_int() == 10
def test_instance_callables(klass):
assert klass.get_attr_int() == 0
klass.set_attr_int(10)
assert klass.get_attr_int() == 10
def test_slot_call(klass):
klass.set_attr_int(33)
assert klass(2) == 66
def test_slot_delitem(klass):
original_count = klass.count()
assert klass[2] == 2
del klass[2]
assert klass.count() == original_count - 1
assert klass[2] == 3
def test_slot_eq(klass, module):
other = module.Klass()
assert klass == other
klass.set_attr_int(10)
assert not (klass == other)
assert not (klass == 100)
def test_slot_getitem(klass):
assert klass[2] == 2
with pytest.raises(IndexError):
klass[-1]
with pytest.raises(IndexError):
klass[klass.count()]
def test_slot_len(klass):
assert klass.count() == len(klass)
def test_slot_neg(klass):
klass.set_attr_int(10)
assert -klass == -10
def test_slot_setitem(klass):
assert klass[2] == 2
klass[2] = 20
assert klass[2] == 20
with pytest.raises(IndexError):
klass[-1] = 0
with pytest.raises(IndexError):
klass[klass.count()] = 0
|