apache-ignite

Форк
0
/
check_enum_constructible.py 
72 строки · 2.1 Кб
1
# Licensed to the Apache Software Foundation (ASF) under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#    http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""
17
Checks IntEnum enhancement.
18
"""
19

20
from enum import IntEnum
21

22
import pytest
23
from ignitetest.utils.enum import constructible
24

25

26
@constructible
27
class ConnectType(IntEnum):
28
    """
29
    Example of IntEnum.
30
    """
31
    UDP = 0
32
    TCP = 1
33
    HTTP = 2
34

35

36
check_params = []
37

38
for name, value in ConnectType.__members__.items():
39
    check_params.append([name, value])
40
    check_params.append([int(value), value])
41
    check_params.append([value, value])
42

43

44
class CheckEnumConstructible:
45
    """
46
    Basic test of IntEnum decorated with @constructible.
47
    """
48
    @pytest.mark.parametrize(
49
        ['input_value', 'expected_value'],
50
        check_params
51
    )
52
    def check_construct_from(self, input_value, expected_value):
53
        """Basic checks."""
54
        with ConnectType.construct_from(input_value) as conn_type:
55
            assert conn_type is expected_value
56

57
    @pytest.mark.parametrize(
58
        ['input_value'],
59
        [[val] for val in [-1, .6, 'test']]
60
    )
61
    def check_invalid_input(self, input_value):
62
        """Check invalid input."""
63
        with pytest.raises(Exception):
64
            ConnectType.construct_from(input_value)
65

66
    def check_invalid_usage(self):
67
        """Check invalid type decoration."""
68
        with pytest.raises(AssertionError):
69
            class SimpleClass:
70
                """Cannot be decorated"""
71

72
            constructible(SimpleClass)
73

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.