Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to skip interactive tests & fix of test #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pystray/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class documentation.
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:
Expand Down
33 changes: 33 additions & 0 deletions tests/icon_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import unittest

Expand Down Expand Up @@ -107,7 +108,19 @@ def for_notification(test):
return lambda *a: None


def interactive_test(test):
"""Marks a test as interactive, which prevents it from being run when environment
variable "TEST_SKIP_INTERACTIVE" is set to "1".

:param test: The test.
"""
return unittest.skipIf(
os.environ["TEST_SKIP_INTERACTIVE"] == "1",
"skip interactive test")


class IconTest(unittest.TestCase):
@interactive_test
def test_set_icon(self):
"""Tests that updating the icon works.
"""
Expand All @@ -126,6 +139,7 @@ def _():
self,
'Did an alternating %s, and %s icon appear?', colors1, colors2)

@interactive_test
def test_set_icon_after_constructor(self):
"""Tests that updating the icon works.
"""
Expand All @@ -141,6 +155,7 @@ def _():
self,
'Did an icon appear?')

@interactive_test
def test_set_icon_to_none(self):
"""Tests that setting the icon to None hides it.
"""
Expand All @@ -157,6 +172,7 @@ def _():
self,
'Did the %s icon disappear?', colors)

@interactive_test
def test_title(self):
"""Tests that initialising with a title works.
"""
Expand All @@ -171,6 +187,7 @@ def _():
self,
'Did an %s icon with the title "%s" appear?', colors, title)

@interactive_test
def test_title_set_hidden(self):
"""Tests that setting the title of a hidden icon works.
"""
Expand All @@ -186,6 +203,7 @@ def _():
self,
'Did a %s icon with the title "%s" appear?', colors, title)

@interactive_test
def test_title_set_visible(self):
"""Tests that setting the title of a visible icon works.
"""
Expand All @@ -212,6 +230,7 @@ def _():
ico.visible = True
self.assertTrue(ico.visible)

@interactive_test
def test_visible_set(self):
"""Tests that showing a simple icon works.
"""
Expand All @@ -238,6 +257,7 @@ def _():
finally:
ico.visible = False

@interactive_test
def test_show_hide(self):
"""Tests that showing and hiding the icon works.
"""
Expand All @@ -256,6 +276,7 @@ def _():
'Did a flashing %s icon appear?', colors)

@for_default_action
@interactive_test
def test_activate(self):
"""Tests that ``on_activate`` is correctly called.
"""
Expand All @@ -274,6 +295,7 @@ def _():
say('Click the icon')
q.get(timeout=TIMEOUT)

@interactive_test
def test_activate_with_default(self):
"""Tests that the default menu item is activated when activating icon.
"""
Expand All @@ -294,6 +316,7 @@ def _():
q.get(timeout=TIMEOUT)

@for_menu
@interactive_test
def test_menu_construct(self):
"""Tests that the menu is constructed.
"""
Expand All @@ -311,6 +334,7 @@ def _():
'Was it\n%s?' % str(ico.menu))

@for_menu
@interactive_test
def test_menu_activate(self):
"""Tests that the menu can be activated.
"""
Expand All @@ -331,6 +355,7 @@ def _():
q.get(timeout=TIMEOUT)

@for_menu
@interactive_test
def test_menu_activate_method(self):
"""Tests that the menu can be activated and a method can be used.
"""
Expand All @@ -353,6 +378,7 @@ def _():
q.get(timeout=TIMEOUT)

@for_menu
@interactive_test
def test_menu_activate_submenu(self):
"""Tests that an item in a submenu can be activated.
"""
Expand All @@ -375,6 +401,7 @@ def _():
q.get(timeout=TIMEOUT)

@for_default_action
@interactive_test
def test_menu_invisble(self):
"""Tests that a menu consisting of only empty items does not show.
"""
Expand All @@ -395,6 +422,7 @@ def _():
q.get(timeout=TIMEOUT)

@for_menu
@interactive_test
def test_menu_dynamic(self):
"""Tests that a dynamic menu works.
"""
Expand Down Expand Up @@ -424,6 +452,7 @@ def _():

@for_default_action
@for_menu
@interactive_test
def test_menu_dynamic_show_hide(self):
"""Tests that a dynamic menu that is hidden works as expected.
"""
Expand Down Expand Up @@ -457,6 +486,7 @@ def _():
'Was it\n%s?' % str(ico.menu))

@for_menu_radio
@interactive_test
def test_menu_radio(self):
"""Tests that mutually exclusive items are displayed separately.
"""
Expand All @@ -474,6 +504,7 @@ def _():
'Was <Item 2> displayed differently from <Item 1>?')

@for_menu_radio
@interactive_test
def test_menu_enabled(self):
"""Tests that menu items can be disabled.
"""
Expand All @@ -491,6 +522,7 @@ def _():
'Was <Item 1> enabled and <Item 2> disabled?')

@for_notification
@interactive_test
def test_show_notification(self):
"""Tests that generation of a notification works.
"""
Expand All @@ -505,6 +537,7 @@ def _():
'Did a notification appear?')

@for_notification
@interactive_test
def test_hide_notification(self):
"""Tests that a notification can be removed again.
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/menu_descriptor_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def test_menu_construct_from_none(self):
"""Tests menu construction.
"""
self.assertEqual(
'',
'\n' + str(menu(None)))
'', str(menu(None)))

def test_menu_construct_with_submenu(self):
"""Tests menu construction.
Expand Down