File: test_atomref.py

package info (click to toggle)
python-atom 0.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,616 kB
  • sloc: cpp: 9,040; python: 6,249; makefile: 123
file content (40 lines) | stat: -rw-r--r-- 938 bytes parent folder | download | duplicates (2)
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
# --------------------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------------------
import gc

import pytest

from atom.api import Atom, atomref


def test_live_atomref():
    """Test a live atomref."""
    atom = Atom()
    ref = atomref(atom)

    assert ref is atomref(atom)
    assert ref and ref() is atom
    assert "AtomRef" in repr(ref)

    ref.__sizeof__()

    with pytest.raises(TypeError):
        atomref(object())


def test_dead_atomref():
    """Test a dead atomref."""
    atom = Atom()
    ref = atomref(atom)
    del atom
    gc.collect()

    assert not ref and ref() is None
    assert "AtomRef" in repr(ref)

    ref.__sizeof__()