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
|
# --------------------------------------------------------------------------------------
# Copyright (c) 2018-2024, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# --------------------------------------------------------------------------------------
"""Test the signal connectors."""
import gc
import operator
import sys
from collections import Counter
import pytest
from atom.api import Atom, Signal
def test_signalconnector_lifecycle():
"""Test creating and destroying an event binder.
We create enough event binder to exceed the freelist length and fully
deallocate some.
"""
class SignalAtom(Atom):
s = Signal()
signal_connectors = [SignalAtom.s for i in range(512)]
for i, e in enumerate(signal_connectors):
signal_connectors[i] = None
del e
gc.collect()
atom = SignalAtom()
sc = atom.s
# Under Python 3.9+ heap allocated type instance keep a reference to the
# type
referents = [SignalAtom.s, atom, type(sc)]
assert Counter(gc.get_referents(sc)) == Counter(referents)
def test_signalconnector_cmp():
"""Test comparing event binders."""
class EventAtom(Atom):
s1 = Signal()
s2 = Signal()
a = EventAtom()
assert a.s1 == a.s1
assert not a.s1 == a.s2
assert not a.s1 == 1
if sys.version_info >= (3,):
for op in ("lt", "le", "gt", "ge"):
with pytest.raises(TypeError):
getattr(operator, op)(a.s1, 1)
|