diff --git a/test/test_soi.py b/test/test_soi.py index 1c60de5945a177e67aa7205b2e9befa08c5235f0..29f73a85c083e0b003005f7ec4f66d68da12b13a 100644 --- a/test/test_soi.py +++ b/test/test_soi.py @@ -14,7 +14,7 @@ import unittest from PySide2.QtWidgets import QApplication, QWidget from PySide2 import QtGui from PySide2.QtGui import QPalette, QColor -from soitool.soi import SOI +from soitool.soi import SOI, ModuleLargerThanBinError from soitool.modules.module_base import ModuleBase if isinstance(QtGui.qApp, type(None)): @@ -157,3 +157,43 @@ class TestSOI(unittest.TestCase): self.soi.add_reorganization_listener(listener) self.soi.reorganize() self.assertTrue(listener_was_called) + + def test_reorganize_of_too_big_module(self): + """Test exception thrown by reorganize in case of too large modules.""" + maximum_width = self.soi.CONTENT_WIDTH + maximum_height = self.soi.CONTENT_HEIGHT - self.soi.HEADER_HEIGHT + + module_too_wide = { + "widget": TestModule("red", maximum_width + 1, 100), + "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"}, + } + module_too_tall = { + "widget": TestModule("red", 100, maximum_height + 1), + "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"}, + } + module_maximum_size = { + "widget": TestModule("red", maximum_width, maximum_height), + "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"}, + } + + # too wide module should raise exception + self.soi.modules = [module_too_wide] + self.assertRaises( + ModuleLargerThanBinError, self.soi.reorganize, + ) + + # too tall module should raise exception + self.soi.modules = [module_too_tall] + self.assertRaises( + ModuleLargerThanBinError, self.soi.reorganize, + ) + + # module with maximum size shouldn't cause any exception + self.soi.modules = [module_maximum_size] + try: + self.soi.reorganize() + except ModuleLargerThanBinError: + self.fail( + "ModuleLargerThanBinError was raised even though module was " + "not too large" + )