Skip to content

Commit

Permalink
Adopt tests and logging
Browse files Browse the repository at this point in the history
old python versions do not support cumulative names for Flag unions.
  • Loading branch information
penguinolog committed Jan 15, 2024
1 parent 62f19d3 commit f037fe5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_basic_sizing(self) -> None:

self.assertEqual(
"Columns widget contents flags not allow to determine supported render kind:\n"
"BOX|WH_WEIGHT,FLOW|FIXED|WH_GIVEN\n"
"BOX WEIGHT, FIXED|FLOW GIVEN\n"
"Using fallback hardcoded BOX|FLOW sizing kind.",
str(ctx.warnings[0].message),
)
Expand Down
2 changes: 1 addition & 1 deletion urwid/widget/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def sizing(self) -> frozenset[Sizing]:
if not supported:
warnings.warn(
f"Columns widget contents flags not allow to determine supported render kind:\n"
f"{','.join(flag.name for flag in flags)}\n"
f"{', '.join(sorted(flag.log_string for flag in flags))}\n"
f"Using fallback hardcoded BOX|FLOW sizing kind.",
ColumnsWarning,
stacklevel=3,
Expand Down
30 changes: 30 additions & 0 deletions urwid/widget/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import typing
import warnings

from .constants import Sizing, WHSettings

if typing.TYPE_CHECKING:
from collections.abc import Iterator

Expand All @@ -20,6 +22,34 @@ class _ContainerElementSizingFlag(enum.IntFlag):
WH_PACK = enum.auto()
WH_GIVEN = enum.auto()

@property
def reverse_flag(self) -> tuple[frozenset(Sizing), WHSettings | None]:
"""Get flag in public API format."""
sizing: set[Sizing] = set()
render: set[WHSettings] = set()

Check failure on line 29 in urwid/widget/container.py

View workflow job for this annotation

GitHub Actions / Check with Ruff

Ruff (F841)

urwid/widget/container.py:29:9: F841 Local variable `render` is assigned to but never used

if self & self.BOX:
sizing.add(Sizing.BOX)
if self & self.FLOW:
sizing.add(Sizing.FLOW)
if self & self.FIXED:
sizing.add(Sizing.FIXED)

if self & self.WH_WEIGHT:
return frozenset(sizing), WHSettings.WEIGHT
if self & self.WH_PACK:
return frozenset(sizing), WHSettings.PACK
if self & self.WH_GIVEN:
return frozenset(sizing), WHSettings.GIVEN
return frozenset(sizing), None

@property
def log_string(self) -> str:
"""Get desctiprion in public API format."""
sizing, render = self.reverse_flag
render_string = f" {render.upper()}" if render else ""
return "|".join(sorted(mode.upper() for mode in sizing)) + render_string


class WidgetContainerMixin:
"""
Expand Down

0 comments on commit f037fe5

Please sign in to comment.