Beispiel #1
0
    def test_safe_uuid_enum(self):
        class CheckedSafeUUID(enum.Enum):
            safe = 0
            unsafe = -1
            unknown = None

        enum._test_simple_enum(CheckedSafeUUID, py_uuid.SafeUUID)
Beispiel #2
0
    def test_sort_stats_enum(self):
        for member in SortKey:
            self.stats.sort_stats(member)
            self.assertEqual(
                self.stats.sort_type,
                self.stats.sort_arg_dict_default[member.value][-1])

        class CheckedSortKey(StrEnum):
            CALLS = 'calls', 'ncalls'
            CUMULATIVE = 'cumulative', 'cumtime'
            FILENAME = 'filename', 'module'
            LINE = 'line'
            NAME = 'name'
            NFL = 'nfl'
            PCALLS = 'pcalls'
            STDNAME = 'stdname'
            TIME = 'time', 'tottime'

            def __new__(cls, *values):
                value = values[0]
                obj = str.__new__(cls, value)
                obj._value_ = value
                for other_value in values[1:]:
                    cls._value2member_map_[other_value] = obj
                obj._all_values = values
                return obj

        _test_simple_enum(CheckedSortKey, SortKey)
Beispiel #3
0
    def test_eventtype_enum(self):
        class CheckedEventType(enum.StrEnum):
            KeyPress = '2'
            Key = KeyPress
            KeyRelease = '3'
            ButtonPress = '4'
            Button = ButtonPress
            ButtonRelease = '5'
            Motion = '6'
            Enter = '7'
            Leave = '8'
            FocusIn = '9'
            FocusOut = '10'
            Keymap = '11'  # undocumented
            Expose = '12'
            GraphicsExpose = '13'  # undocumented
            NoExpose = '14'  # undocumented
            Visibility = '15'
            Create = '16'
            Destroy = '17'
            Unmap = '18'
            Map = '19'
            MapRequest = '20'
            Reparent = '21'
            Configure = '22'
            ConfigureRequest = '23'
            Gravity = '24'
            ResizeRequest = '25'
            Circulate = '26'
            CirculateRequest = '27'
            Property = '28'
            SelectionClear = '29'  # undocumented
            SelectionRequest = '30'  # undocumented
            Selection = '31'  # undocumented
            Colormap = '32'
            ClientMessage = '33'  # undocumented
            Mapping = '34'  # undocumented
            VirtualEvent = '35'  # undocumented
            Activate = '36'
            Deactivate = '37'
            MouseWheel = '38'

        enum._test_simple_enum(CheckedEventType, tkinter.EventType)
Beispiel #4
0
    def test_enums(self):
        for name in dir(signal):
            sig = getattr(signal, name)
            if name in {'SIG_DFL', 'SIG_IGN'}:
                self.assertIsInstance(sig, signal.Handlers)
            elif name in {'SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'}:
                self.assertIsInstance(sig, signal.Sigmasks)
            elif name.startswith('SIG') and not name.startswith('SIG_'):
                self.assertIsInstance(sig, signal.Signals)
            elif name.startswith('CTRL_'):
                self.assertIsInstance(sig, signal.Signals)
                self.assertEqual(sys.platform, "win32")

        CheckedSignals = enum._old_convert_(
            enum.IntEnum,
            'Signals',
            'signal',
            lambda name: name.isupper() and
            (name.startswith('SIG') and not name.startswith('SIG_')
             ) or name.startswith('CTRL_'),
            source=signal,
        )
        enum._test_simple_enum(CheckedSignals, signal.Signals)

        CheckedHandlers = enum._old_convert_(
            enum.IntEnum,
            'Handlers',
            'signal',
            lambda name: name in ('SIG_DFL', 'SIG_IGN'),
            source=signal,
        )
        enum._test_simple_enum(CheckedHandlers, signal.Handlers)

        Sigmasks = getattr(signal, 'Sigmasks', None)
        if Sigmasks is not None:
            CheckedSigmasks = enum._old_convert_(
                enum.IntEnum,
                'Sigmasks',
                'signal',
                lambda name: name in
                ('SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'),
                source=signal,
            )
            enum._test_simple_enum(CheckedSigmasks, Sigmasks)