• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nocarryr / tslumd / 5833948469

pending completion
5833948469

push

github

nocarryr
Use pytest_asyncio.fixture for teardown fixtures

841 of 897 relevant lines covered (93.76%)

2.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.44
/src/tslumd/common.py
1
import enum
3✔
2
from typing import Tuple, Iterable
3✔
3

4
__all__ = ('TallyColor', 'TallyType', 'TallyState', 'MessageType', 'TallyKey')
3✔
5

6
class TallyColor(enum.IntFlag):
3✔
7
    """Color enum for tally indicators
8

9
    Since this is an :class:`~enum.IntFlag`, its members can be combined using
10
    bitwise operators, making :attr:`AMBER` a combination of
11
    :attr:`RED` and :attr:`GREEN`
12

13
    This allows merging one color with another
14

15
    >>> from tslumd import TallyColor
16
    >>> TallyColor.RED
17
    <TallyColor.RED: 1>
18
    >>> TallyColor.GREEN
19
    <TallyColor.GREEN: 2>
20
    >>> TallyColor.AMBER
21
    <TallyColor.AMBER: 3>
22
    >>> TallyColor.RED | TallyColor.GREEN
23
    <TallyColor.AMBER: 3>
24

25

26
    .. versionchanged:: 0.0.4
27
        Bitwise operators
28
    """
29
    OFF = 0             #: Off
3✔
30
    RED = 1             #: Red
3✔
31
    GREEN = 2           #: Green
3✔
32
    AMBER = RED | GREEN #: Amber
3✔
33

34
    @staticmethod
3✔
35
    def from_str(s: str) -> 'TallyColor':
3✔
36
        """Return the member matching the given name (case-insensitive)
37

38
        >>> TallyColor.from_str('RED')
39
        <TallyColor.RED: 1>
40
        >>> TallyColor.from_str('green')
41
        <TallyColor.GREEN: 2>
42
        >>> TallyColor.from_str('Amber')
43
        <TallyColor.AMBER: 3>
44

45
        .. versionadded:: 0.0.5
46
        """
47
        return getattr(TallyColor, s.upper())
3✔
48

49
    def to_str(self) -> str:
3✔
50
        """The member name as a string
51

52
        >>> TallyColor.RED.to_str()
53
        'RED'
54
        >>> TallyColor.GREEN.to_str()
55
        'GREEN'
56
        >>> TallyColor.AMBER.to_str()
57
        'AMBER'
58
        >>> (TallyColor.RED | TallyColor.GREEN).to_str()
59
        'AMBER'
60

61
        .. versionadded:: 0.0.5
62
        """
63
        return self.name
3✔
64

65
    def __str__(self):
3✔
66
        return self.name
3✔
67

68
    def __format__(self, format_spec):
3✔
69
        if format_spec == '':
3✔
70
            return str(self)
3✔
71
        return super().__format__(format_spec)
×
72

73
class TallyType(enum.IntFlag):
3✔
74
    """Enum for the three tally display types in the UMD protocol
75

76
    Since this is an :class:`~enum.IntFlag`, its members can be combined using
77
    bitwise operators. The members can then be iterated over to retrieve the
78
    individual "concrete" values of :attr:`rh_tally`, :attr:`txt_tally`
79
    and :attr:`lh_tally`
80

81
    >>> from tslumd import TallyType
82
    >>> list(TallyType.rh_tally)
83
    [<TallyType.rh_tally: 1>]
84
    >>> list(TallyType.rh_tally | TallyType.txt_tally)
85
    [<TallyType.rh_tally: 1>, <TallyType.txt_tally: 2>]
86
    >>> list(TallyType.all_tally)
87
    [<TallyType.rh_tally: 1>, <TallyType.txt_tally: 2>, <TallyType.lh_tally: 4>]
88

89
    .. versionchanged:: 0.0.4
90
        Added support for bitwise operators and member iteration
91
    """
92
    no_tally = 0  #: No-op
3✔
93
    rh_tally = 1  #: :term:`Right-hand tally <rh_tally>`
3✔
94
    txt_tally = 2 #: :term:`Text tally <txt_tally>`
3✔
95
    lh_tally = 4  #: :term:`Left-hand tally <lh_tally>`
3✔
96
    all_tally = rh_tally | txt_tally | lh_tally
3✔
97
    """Combination of all tally types
98

99
    .. versionadded:: 0.0.4
100
    """
101

102
    @property
3✔
103
    def is_iterable(self) -> bool:
3✔
104
        """Returns ``True`` if this is a combination of multiple members
105

106
        (meaning it must be iterated over)
107

108
        .. versionadded:: 0.0.5
109
        """
110
        if self == TallyType.all_tally:
3✔
111
            return True
3✔
112
        return self.name is None
3✔
113

114
    @classmethod
3✔
115
    def all(cls) -> Iterable['TallyType']:
3✔
116
        """Iterate over all members, excluding :attr:`no_tally` and :attr:`all_tally`
117

118
        .. versionadded:: 0.0.4
119
        """
120
        for ttype in cls:
3✔
121
            if ttype != TallyType.no_tally and ttype != TallyType.all_tally:
3✔
122
                yield ttype
3✔
123

124
    @staticmethod
3✔
125
    def from_str(s: str) -> 'TallyType':
3✔
126
        """Create an instance from a string of member name(s)
127

128
        The string can be a single member or multiple member names separated by
129
        a "|". For convenience, the names may be shortened by omitting the
130
        ``"_tally"`` portion from the end ("rh" == "rh_tally", etc)
131

132
        >>> TallyType.from_str('rh_tally')
133
        <TallyType.rh_tally: 1>
134
        >>> TallyType.from_str('rh|txt_tally')
135
        <TallyType.txt_tally|rh_tally: 3>
136
        >>> TallyType.from_str('rh|txt|lh')
137
        <TallyType.all_tally: 7>
138
        >>> TallyType.from_str('all')
139
        <TallyType.all_tally: 7>
140

141
        .. versionadded:: 0.0.5
142
        """
143
        if '|' in s:
3✔
144
            result = TallyType.no_tally
3✔
145
            for name in s.split('|'):
3✔
146
                result |= TallyType.from_str(name)
3✔
147
            return result
3✔
148
        s = s.lower()
3✔
149
        if not s.endswith('_tally'):
3✔
150
            s = f'{s}_tally'
3✔
151
        return getattr(TallyType, s)
3✔
152

153
    def to_str(self) -> str:
3✔
154
        """Create a string representation suitable for use in :meth:`from_str`
155

156
        >>> tt = TallyType.rh_tally
157
        >>> tt.to_str()
158
        'rh_tally'
159
        >>> tt |= TallyType.txt_tally
160
        >>> tt.to_str()
161
        'rh_tally|txt_tally'
162
        >>> tt |= TallyType.lh_tally
163
        >>> tt.to_str()
164
        'all_tally'
165

166
        .. versionadded:: 0.0.5
167
        """
168
        if self.name is None:
3✔
169
            return '|'.join((obj.name for obj in self))
3✔
170
        return self.name
3✔
171

172
    def __iter__(self):
3✔
173
        for ttype in self.all():
3✔
174
            if ttype in self:
3✔
175
                yield ttype
3✔
176

177
class TallyState(enum.IntFlag):
3✔
178
    OFF = 0     #: Off
3✔
179
    PREVIEW = 1 #: Preview
3✔
180
    PROGRAM = 2 #: Program
3✔
181

182
class MessageType(enum.Enum):
3✔
183
    """Message type
184

185
    .. versionadded:: 0.0.2
186
    """
187
    _unset = 0
3✔
188
    display = 1 #: A message containing tally display information
3✔
189
    control = 2 #: A message containing control data
3✔
190

191
TallyKey = Tuple[int, int]
3✔
192
"""A tuple of (:attr:`screen_index <.Screen.index>`,
3✔
193
:attr:`tally_index <.Tally.index>`) to uniquely identify a single :class:`.Tally`
194
within its :class:`.Screen`
195
"""
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc