-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from martinjankoehler/pdk-arg-help
argparse helpers: for StrEnums, use the member value instead of the member name
- Loading branch information
Showing
2 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# -------------------------------------------------------------------------------- | ||
# SPDX-FileCopyrightText: 2024 Martin Jan Köhler and Harald Pretl | ||
# Johannes Kepler University, Institute for Integrated Circuits. | ||
# | ||
# This file is part of KPEX | ||
# (see https://github.com/martinjankoehler/klayout-pex). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# -------------------------------------------------------------------------------- | ||
# | ||
|
||
from __future__ import annotations | ||
|
||
import allure | ||
from enum import StrEnum, IntEnum | ||
from typing import * | ||
import unittest | ||
|
||
from klayout_pex.util.argparse_helpers import render_enum_help | ||
|
||
|
||
@allure.parent_suite("Unit Tests") | ||
@allure.tag("Enum", "Help", "Util") | ||
class Test(unittest.TestCase): | ||
def test_render_enum_help__nodefault__intenum(self): | ||
class IntEnum1(IntEnum): | ||
CASE1 = 1 | ||
CASE2 = 2 | ||
|
||
expected_string = "--arg ∈ {'case1', 'case2'}" | ||
obtained_string = render_enum_help(enum_cls=IntEnum1, topic="--arg", print_default=False) | ||
assert obtained_string == expected_string | ||
|
||
def test_render_enum_help__default__intenum(self): | ||
class IntEnum2(IntEnum): | ||
CASE1 = 1 | ||
CASE2 = 2 | ||
DEFAULT = CASE1 | ||
|
||
expected_string = "--arg ∈ {'case1', 'case2', 'default'}.\nDefaults to 'case1'" | ||
obtained_string = render_enum_help(enum_cls=IntEnum2, topic="--arg", print_default=True) | ||
assert obtained_string == expected_string | ||
|
||
def test_render_enum_help__default__strenum(self): | ||
class StrEnum1(StrEnum): | ||
CASE1 = "Case1" | ||
CASE2 = "Case2" | ||
DEFAULT = CASE1 | ||
|
||
expected_string = "--arg ∈ {'Case1', 'Case2', 'default'}.\nDefaults to 'Case1'" | ||
obtained_string = render_enum_help(enum_cls=StrEnum1, topic="--arg", print_default=True) | ||
assert obtained_string == expected_string | ||
|
||
def test_render_enum_help__default__strenum__lowercased(self): | ||
class StrEnum1(StrEnum): | ||
CASE1 = "Case1" | ||
CASE2 = "Case2" | ||
DEFAULT = CASE1 | ||
|
||
expected_string = "--arg ∈ {'case1', 'case2', 'default'}.\nDefaults to 'case1'" | ||
obtained_string = render_enum_help(enum_cls=StrEnum1, topic="--arg", | ||
print_default=True, | ||
lowercase_strenum=True) | ||
assert obtained_string == expected_string |