Fix bug #711 and add some tests

This commit is contained in:
Raoul Snyman 2021-08-06 08:14:48 -07:00
parent e048348890
commit 322f4f1d5b
2 changed files with 35 additions and 2 deletions

View File

@ -340,8 +340,8 @@ class ScreenList(metaclass=Singleton):
:param screen_dict: The dict describing the screen to match. :param screen_dict: The dict describing the screen to match.
""" """
for screen in self.screens: for screen in self.screens:
if screen.to_dict()['geometry'] == screen_dict['geometry'] \ if screen.to_dict().get('geometry') == screen_dict.get('geometry') \
and screen.is_primary == screen_dict['is_primary']: and screen.is_primary == screen_dict.get('is_primary'):
return screen.number return screen.number
return None return None

View File

@ -253,6 +253,39 @@ def test_screen_list_on_primary_changed(mocked_screens, settings, registry):
assert screen_list.screens[1].is_primary is True assert screen_list.screens[1].is_primary is True
def test_screen_list_get_screen_number():
"""Test ScreenList().get_screen_number() method works with a given dictionary"""
# GIVEN: A screen list with an incomplete screen
screen_list = ScreenList()
screen_list.screens = [
Screen(1, QtCore.QRect(0, 0, 1024, 768), is_primary=True),
Screen(2, QtCore.QRect(0, 1024, 1024, 768), is_primary=False)
]
# When searching for a screen number
result = screen_list.get_screen_number({"geometry": {"x": 0, "y": 1024, "width": 1024, "height": 768},
"is_primary": False})
# THEN: The result should be None
assert result == 2, 'ScreenList.get_screen_number() should return 2'
def test_screen_list_get_screen_number_incomplete():
"""Test that when the settings are incomplete (don't have a geometry) that the has_number method still works"""
# GIVEN: A screen list with an incomplete screen
screen_list = ScreenList()
screen_list.screens = [
Screen(1, QtCore.QRect(0, 0, 1024, 768), is_primary=True),
Screen(2, QtCore.QRect(0, 1024, 1024, 768), is_primary=False)
]
# When searching for a screen number
result = screen_list.get_screen_number({"is_primary": True})
# THEN: The result should be None
assert result is None, 'ScreenList.get_screen_number() should return None'
def test_screen_from_dict(): def test_screen_from_dict():
"""Test that all the correct attributes are set when creating a screen from a dictionary""" """Test that all the correct attributes are set when creating a screen from a dictionary"""
# GIVEN: A dictionary of values # GIVEN: A dictionary of values