+ 1#
+ 2# --------------------------------------------------------------------------------
+ 3# SPDX-FileCopyrightText: 2024 Martin Jan Köhler and Harald Pretl
+ 4# Johannes Kepler University, Institute for Integrated Circuits.
+ 5#
+ 6# This file is part of KPEX
+ 7# (see https://github.com/martinjankoehler/klayout-pex).
+ 8#
+ 9# This program is free software: you can redistribute it and/or modify
+ 10# it under the terms of the GNU General Public License as published by
+ 11# the Free Software Foundation, either version 3 of the License, or
+ 12# (at your option) any later version.
+ 13#
+ 14# This program is distributed in the hope that it will be useful,
+ 15# but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 17# GNU General Public License for more details.
+ 18#
+ 19# You should have received a copy of the GNU General Public License
+ 20# along with this program. If not, see <http://www.gnu.org/licenses/>.
+ 21# SPDX-License-Identifier: GPL-3.0-or-later
+ 22# --------------------------------------------------------------------------------
+ 23#
+ 24
+ 25from __future__ import annotations
+ 26
+ 27import allure
+ 28from enum import StrEnum, IntEnum
+ 29from typing import *
+ 30import unittest
+ 31
+ 32from klayout_pex.util.argparse_helpers import render_enum_help
+ 33
+ 34
+ 35@allure.parent_suite("Unit Tests")
+ 36@allure.tag("Enum", "Help", "Util")
+ 37class Test(unittest.TestCase):
+ 38 def test_render_enum_help__nodefault__intenum(self):
+ 39 class IntEnum1(IntEnum):
+ 40 CASE1 = 1
+ 41 CASE2 = 2
+ 42
+ 43 expected_string = "--arg ∈ {'case1', 'case2'}"
+ 44 obtained_string = render_enum_help(enum_cls=IntEnum1, topic="--arg", print_default=False)
+ 45 assert obtained_string == expected_string
+ 46
+ 47 def test_render_enum_help__default__intenum(self):
+ 48 class IntEnum2(IntEnum):
+ 49 CASE1 = 1
+ 50 CASE2 = 2
+ 51 DEFAULT = CASE1
+ 52
+ 53 expected_string = "--arg ∈ {'case1', 'case2', 'default'}.\nDefaults to 'case1'"
+ 54 obtained_string = render_enum_help(enum_cls=IntEnum2, topic="--arg", print_default=True)
+ 55 assert obtained_string == expected_string
+ 56
+ 57 def test_render_enum_help__default__strenum(self):
+ 58 class StrEnum1(StrEnum):
+ 59 CASE1 = "Case1"
+ 60 CASE2 = "Case2"
+ 61 DEFAULT = CASE1
+ 62
+ 63 expected_string = "--arg ∈ {'Case1', 'Case2', 'default'}.\nDefaults to 'Case1'"
+ 64 obtained_string = render_enum_help(enum_cls=StrEnum1, topic="--arg", print_default=True)
+ 65 assert obtained_string == expected_string
+ 66
+ 67 def test_render_enum_help__default__strenum__lowercased(self):
+ 68 class StrEnum1(StrEnum):
+ 69 CASE1 = "Case1"
+ 70 CASE2 = "Case2"
+ 71 DEFAULT = CASE1
+ 72
+ 73 expected_string = "--arg ∈ {'case1', 'case2', 'default'}.\nDefaults to 'case1'"
+ 74 obtained_string = render_enum_help(enum_cls=StrEnum1, topic="--arg",
+ 75 print_default=True,
+ 76 lowercase_strenum=True)
+ 77 assert obtained_string == expected_string
+
+