Skip to content

Commit

Permalink
Merge pull request #239 from vojtechtrefny/master_size-limits-set-fix
Browse files Browse the repository at this point in the history
Fix ValueError when trying to set both upper and lower size limits
  • Loading branch information
vojtechtrefny authored Sep 25, 2020
2 parents 3ef1ab5 + 27faf3d commit 10e58f4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
3 changes: 2 additions & 1 deletion blivetgui/blivetgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def supported_filesystems(self):
if self._supported_filesystems:
return self._supported_filesystems

self._supported_filesystems = self.client.remote_call("get_supported_filesystems")
self._supported_filesystems = self.client.remote_call("get_supported_filesystems",
self.installer_mode)
return self._supported_filesystems

def initialize(self):
Expand Down
6 changes: 4 additions & 2 deletions blivetgui/dialogs/add_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,10 @@ def on_filesystems_combo_changed(self, _combo):
self.show_widgets(["label"])

# update size
self.size_area.min_size_limit = self._get_min_size_limit()
self.size_area.max_size_limit = self._get_max_size_limit()
min_size_limit = self._get_min_size_limit()
max_size_limit = self._get_max_size_limit()

self.size_area.set_size_limits(min_size_limit, max_size_limit)

def add_name_chooser(self):
label_label = Gtk.Label(label=_("Label:"), xalign=1)
Expand Down
18 changes: 17 additions & 1 deletion blivetgui/dialogs/size_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def min_size_limit(self, new_size):
if new_size <= 0:
raise ValueError("Size limit must be greater than zero.")

if new_size >= self.max_size:
if new_size > self.max_size:
raise ValueError("Size limit for minimal size cannot be greater than current maximum size.")

self._min_size_limit = new_size
Expand Down Expand Up @@ -183,6 +183,22 @@ def max_size_limit(self, new_size):
if self._parent_area is None:
self.main_chooser.max_size = self.max_size

def set_size_limits(self, min_size_limit, max_size_limit):
""" Set both size limits at once avoiding issues with new size limits being outside of
existing limits. E.g. when changing limits from (1 MiB, 2 MiB) to (256 MiB, 1 GiB)
changing the min limit will fail because it is greater than existing max limit.
"""

if min_size_limit > self.max_size:
self.max_size_limit = max_size_limit
self.min_size_limit = min_size_limit
elif max_size_limit < self.min_size:
self.min_size_limit = min_size_limit
self.max_size_limit = max_size_limit
else:
self.max_size_limit = max_size_limit
self.min_size_limit = min_size_limit

# PUBLIC METHODS
def connect(self, signal_name, signal_handler, *args): # pylint: disable=unused-argument
""" Connect a signal hadler """
Expand Down
22 changes: 22 additions & 0 deletions tests/blivetgui_tests/add_dialog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,28 @@ def test_fs_chooser(self):
self.assertTrue(add_dialog.mountpoint_entry.get_visible())
self.assertTrue(add_dialog.label_entry.get_visible())

def test_fs_chooser_biosboot(self):
parent_device = self._get_parent_device()
free_device = self._get_free_device(parent=parent_device)

_filesystems = self.supported_filesystems[:]
_filesystems.append(formats.biosboot.BIOSBoot())
_filesystems.append(formats.fs.BTRFS())

add_dialog = AddDialog(self.parent_window, parent_device, free_device,
[("free", free_device)], _filesystems,
[], True) # with installer_mode=True

# switch from biosboot to btrfs and ext4 (rhbz#1881472)
add_dialog.filesystems_combo.set_active_id("biosboot")
self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "biosboot")
add_dialog.filesystems_combo.set_active_id("btrfs")
self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "btrfs")
add_dialog.filesystems_combo.set_active_id("biosboot")
self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "biosboot")
add_dialog.filesystems_combo.set_active_id("ext4")
self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "ext4")

def test_md_type(self):
parent_device = self._get_parent_device()
free_device = self._get_free_device(parent=parent_device)
Expand Down
36 changes: 36 additions & 0 deletions tests/blivetgui_tests/size_widgets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,42 @@ def test_40_basic_limits(self):
with self.assertRaises(ValueError):
size_area.max_size_limit = Size(-10) # smaller tnan min size

def test_45_basic_limits_combined(self):
""" Test SizeArea limits functionality without ParentArea """

parents = [MagicMock(device=self._mock_device(), min_size=Size("1 MiB"), max_size=Size("1 GiB"),
reserved_size=Size(0)),
MagicMock(device=self._mock_device(), min_size=Size("1 MiB"), max_size=Size("1 GiB"),
reserved_size=Size(0))]

size_area = SizeArea(device_type="lvm", parents=parents,
min_limit=Size(1), max_limit=Size("200 GiB"),
raid_type=None)

# changing both limits at once
size_area.set_size_limits(Size("100 MiB"), Size("1 GiB"))
self.assertEqual(size_area.min_size, Size("100 MiB"))
self.assertEqual(size_area.max_size, Size("1 GiB"))

size_area.set_size_limits(Size("2 MiB"), Size("10 MiB"))
self.assertEqual(size_area.min_size, Size("2 MiB"))
self.assertEqual(size_area.max_size, Size("10 MiB"))

size_area.set_size_limits(Size("100 MiB"), Size("200 MiB"))
self.assertEqual(size_area.min_size, Size("100 MiB"))
self.assertEqual(size_area.max_size, Size("200 MiB"))

size_area.set_size_limits(Size("2 MiB"), Size("4 MiB"))
self.assertEqual(size_area.min_size, Size("2 MiB"))
self.assertEqual(size_area.max_size, Size("4 MiB"))

size_area.set_size_limits(Size("10 MiB"), Size("10 MiB"))
self.assertEqual(size_area.min_size, Size("10 MiB"))
self.assertEqual(size_area.max_size, Size("10 MiB"))

with self.assertRaises(ValueError):
size_area.set_size_limits(Size("100 MiB"), Size("20 MiB"))

def test_50_advanced_limits(self):
""" Test SizeArea limits functionality with ParentArea """

Expand Down

0 comments on commit 10e58f4

Please sign in to comment.