def test_version(self) -> None: vs = VersionSort() self.assertEqual( sorted([Kernel('4.14.0'), Kernel('5.7.0-foo-rc3'), Kernel('5.7.0-rc3'), Kernel('5.7.0'), Kernel('5.4.0'), Kernel('5.6.10'), Kernel('5.6-frobnicate'), Kernel('5.6.0-frobnicate'), Kernel('5.6.10-frobnicate'), Kernel('4.7.11'), Kernel('5.6.0'), Kernel('5.6.10-rt-rt5'), ], key=vs.key), [Kernel('4.7.11'), Kernel('4.14.0'), Kernel('5.4.0'), Kernel('5.6-frobnicate'), Kernel('5.6.0'), Kernel('5.6.0-frobnicate'), Kernel('5.6.10'), Kernel('5.6.10-frobnicate'), Kernel('5.6.10-rt-rt5'), Kernel('5.7.0-rc3'), Kernel('5.7.0'), Kernel('5.7.0-foo-rc3'), ])
def test_removal_bootloader(self) -> None: td = Path(self.td.name) class MockBootloader(Bootloader): name = 'mock' def __call__(self) -> typing.Iterable[str]: yield str(td / 'does-not-exist') yield str(td / 'kernel.old') self.assertEqual( get_removal_list(self.kernels, sorter=VersionSort(), limit=1, destructive=False, bootloader=MockBootloader()), { self.kernels[2]: [ 'vmlinuz does not exist', 'not referenced by bootloader (mock)' ], self.kernels[3]: [ 'vmlinuz does not exist', 'not referenced by bootloader (mock)' ], })
def test_removal_destructive(self) -> None: self.assertEqual( get_removal_list(self.kernels, sorter=VersionSort(), limit=1, destructive=True), { self.kernels[2]: ['vmlinuz does not exist'], self.kernels[3]: ['vmlinuz does not exist'], self.kernels[0]: ['unwanted'], })
def test_removal_current_stray(self, uname: MagicMock) -> None: uname.return_value = ('Linux', 'localhost', '3.stray', '', 'x86_64') self.assertEqual( get_removal_list(self.kernels, sorter=VersionSort(), limit=1, destructive=True), { self.kernels[3]: ['vmlinuz does not exist'], self.kernels[0]: ['unwanted'], })
def test_removal_no_limit(self) -> None: self.assertEqual( get_removal_list(self.kernels, sorter=VersionSort(), limit=0), { self.kernels[2]: ['vmlinuz does not exist'], self.kernels[3]: ['vmlinuz does not exist'], })
def test_removal_no_bootloader(self) -> None: with self.assertRaises(SystemError): get_removal_list(self.kernels, sorter=VersionSort(), limit=1, destructive=False)