File: test_enum.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 (39 lines) | stat: -rw-r--r-- 1,095 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
33
34
35
36
37
38
39
# --------------------------------------------------------------------------------------
# Copyright (c) 2013-2025, 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 enum member."""

import pytest

from atom.api import Enum


def test_enum():
    """Test manipulating an Enum member."""
    e = Enum("a", "b")
    assert e.items == ("a", "b")
    assert e.default_value_mode[1] == "a"

    e_def = e("b")
    assert e_def is not e
    assert e_def.default_value_mode[1] == "b"
    with pytest.raises(TypeError):
        e("c")

    e_add = e.added("c", "d")
    assert e_add is not e
    assert e_add.items == ("a", "b", "c", "d")

    e_rem = e.removed("a")
    assert e_rem is not e
    assert e_rem.items == ("b",)
    assert e_rem.default_value_mode[1] == "b"
    with pytest.raises(ValueError):
        e.removed("a", "b")

    with pytest.raises(ValueError):
        Enum()