1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
From: Claudius Heine <ch@denx.de>
Date: Mon, 24 Oct 2022 11:24:19 +0200
Subject: Fix test_menu_construct_from_none test case
When `menu(None)` is called, this exception happens:
File "/tmp/pystray-0.19.4/lib/pystray/_base.py", line 661, in cleaned
if not i.visible:
AttributeError: 'NoneType' object has no attribute 'visible'
Adding an `not i or` before that condition will make sure that `None`
will be considered as not visible.
The test itself fails as well:
File "/tmp/pystray-0.19.4/tests/menu_descriptor_tests.py", line 85, in test_menu_construct_from_none
self.assertEqual(
AssertionError: '' != '\n'
Instead just compare if `str(menu(None))` is the empty string.
[Upstream-Status: submitted(https://github.com/moses-palmer/pystray/pull/133)]
---
lib/pystray/_base.py | 2 +-
tests/menu_descriptor_tests.py | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
--- a/lib/pystray/_base.py
+++ b/lib/pystray/_base.py
@@ -662,7 +662,7 @@
def cleaned(items):
was_separator = False
for i in items:
- if not i.visible:
+ if not i or not i.visible:
continue
if i is self.SEPARATOR:
--- a/tests/menu_descriptor_tests.py
+++ b/tests/menu_descriptor_tests.py
@@ -83,8 +83,7 @@
"""Tests menu construction.
"""
self.assertEqual(
- '',
- '\n' + str(menu(None)))
+ '', str(menu(None)))
def test_menu_construct_with_submenu(self):
"""Tests menu construction.
|