debug: Use existing qflags_key logic for Qt 6
The existing logic seems to work fine now (with some adjustments) and results in better output compared to the repr. Partially reverts 111e0c7f3dcccb4d0ff807854cacb6506a93e1f2.
This commit is contained in:
parent
de593e6a8c
commit
b7eb182e74
|
|
@ -174,13 +174,6 @@ def qflags_key(base: Type[_EnumValueType],
|
|||
The keys associated with the flags as a '|' separated string if they
|
||||
could be found. Hex values as a string if not.
|
||||
"""
|
||||
if isinstance(value, enum.Flag):
|
||||
# New-style PyQt 6
|
||||
if value.name is None:
|
||||
# FIXME:qt6 can we do something better here?
|
||||
return repr(value)
|
||||
return value.name
|
||||
|
||||
if klass is None:
|
||||
# We have to store klass here because it will be lost when iterating
|
||||
# over the bits.
|
||||
|
|
@ -194,7 +187,7 @@ def qflags_key(base: Type[_EnumValueType],
|
|||
bits = []
|
||||
names = []
|
||||
mask = 0x01
|
||||
value = int(value) # type: ignore[arg-type]
|
||||
value = qtutils.extract_enum_val(value)
|
||||
while mask <= value:
|
||||
if value & mask:
|
||||
bits.append(mask)
|
||||
|
|
@ -203,7 +196,7 @@ def qflags_key(base: Type[_EnumValueType],
|
|||
# We have to re-convert to an enum type here or we'll sometimes get an
|
||||
# empty string back.
|
||||
enum_value = klass(bit) # type: ignore[call-arg]
|
||||
names.append(qenum_key(base, enum_value))
|
||||
names.append(qenum_key(base, enum_value, klass))
|
||||
return '|'.join(names)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -159,18 +159,20 @@ class TestQFlagsKey:
|
|||
https://github.com/qutebrowser/qutebrowser/issues/42
|
||||
"""
|
||||
|
||||
fixme = pytest.mark.xfail(reason="See issue #42", raises=AssertionError)
|
||||
|
||||
@pytest.mark.parametrize('base, value, klass, expected', [
|
||||
(Qt, Qt.AlignmentFlag.AlignTop, None, 'AlignTop'),
|
||||
pytest.param(Qt, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop, None,
|
||||
'AlignLeft|AlignTop', marks=fixme),
|
||||
'AlignLeft|AlignTop', marks=pytest.mark.qt5_xfail(raises=AssertionError)),
|
||||
(Qt, Qt.AlignmentFlag.AlignCenter, None, 'AlignHCenter|AlignVCenter'),
|
||||
pytest.param(Qt, 0x0021, Qt.AlignmentFlag, 'AlignLeft|AlignTop',
|
||||
marks=fixme),
|
||||
marks=pytest.mark.qt5_xfail(raises=AssertionError)),
|
||||
(Qt, 0x1100, Qt.AlignmentFlag, 'AlignBaseline|0x1000'),
|
||||
(Qt, Qt.DockWidgetArea(0), Qt.DockWidgetArea, 'NoDockWidgetArea'),
|
||||
(Qt, Qt.DockWidgetArea(0), None, 'NoDockWidgetArea'),
|
||||
(Qt, Qt.KeyboardModifier.ShiftModifier, Qt.KeyboardModifier, 'ShiftModifier'),
|
||||
(Qt, Qt.KeyboardModifier.ShiftModifier, None, 'ShiftModifier'),
|
||||
(Qt, Qt.KeyboardModifier.ShiftModifier | Qt.KeyboardModifier.ControlModifier, Qt.KeyboardModifier, 'ShiftModifier|ControlModifier'),
|
||||
pytest.param(Qt, Qt.KeyboardModifier.ShiftModifier | Qt.KeyboardModifier.ControlModifier, None, 'ShiftModifier|ControlModifier', marks=pytest.mark.qt5_xfail(raises=AssertionError)),
|
||||
])
|
||||
def test_qflags_key(self, base, value, klass, expected):
|
||||
flags = debug.qflags_key(base, value, klass=klass)
|
||||
|
|
|
|||
Loading…
Reference in New Issue