apache-ignite
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"""
17Checks IntEnum enhancement.
18"""
19
20from enum import IntEnum21
22import pytest23from ignitetest.utils.enum import constructible24
25
26@constructible
27class ConnectType(IntEnum):28"""29Example of IntEnum.
30"""
31UDP = 032TCP = 133HTTP = 234
35
36check_params = []37
38for name, value in ConnectType.__members__.items():39check_params.append([name, value])40check_params.append([int(value), value])41check_params.append([value, value])42
43
44class CheckEnumConstructible:45"""46Basic test of IntEnum decorated with @constructible.
47"""
48@pytest.mark.parametrize(49['input_value', 'expected_value'],50check_params
51)52def check_construct_from(self, input_value, expected_value):53"""Basic checks."""54with ConnectType.construct_from(input_value) as conn_type:55assert conn_type is expected_value56
57@pytest.mark.parametrize(58['input_value'],59[[val] for val in [-1, .6, 'test']]60)61def check_invalid_input(self, input_value):62"""Check invalid input."""63with pytest.raises(Exception):64ConnectType.construct_from(input_value)65
66def check_invalid_usage(self):67"""Check invalid type decoration."""68with pytest.raises(AssertionError):69class SimpleClass:70"""Cannot be decorated"""71
72constructible(SimpleClass)73