def test_wrong_layout_std(self) -> None: with self.create_layout() as td: with self.assertRaises(SystemError): main([ '--destructive', '-n', '2', '--pretend', '--layout', 'std', '--root', td, '--debug', '--no-mount' ])
def test_wrong_layout_blspec(self) -> None: with self.create_layout() as td: with self.assertRaises(SystemExit) as e: main([ '--destructive', '-n', '2', '--pretend', '--layout', 'blspec', '--root', td, '--debug', '--no-mount' ]) self.assertNotEqual(e.exception.code, 0)
def test_main_list_kernels(self, sout: io.StringIO) -> None: with self.create_layout() as td: self.assertEqual(main(['--list-kernels', '--root', td, '--debug']), 0) val = (x for x in sout.getvalue().splitlines() if not x.startswith('- last modified:')) self.assertEqual( '\n'.join(val), f''' 1.2.4 [None] - config: {td}/boot/config-1.2.4 - modules: {td}/lib/modules/1.2.4 1.2.3 [1.2.3] - systemmap: {td}/boot/System.map-1.2.3 - config: {td}/boot/config-1.2.3 - initramfs: {td}/boot/initrd-1.2.3.img - vmlinuz: {td}/boot/vmlinuz-1.2.3 - modules: {td}/lib/modules/1.2.3 - build: {td}/lib/modules/1.2.3/../../../usr/src/linux 1.2.3.old [1.2.3] - systemmap: {td}/boot/System.map-1.2.3.old - config: {td}/boot/config-1.2.3.old - initramfs: {td}/boot/initrd-1.2.3.img.old - vmlinuz: {td}/boot/vmlinuz-1.2.3.old - modules: {td}/lib/modules/1.2.3 - build: {td}/lib/modules/1.2.3/../../../usr/src/linux 1.2.2 [1.2.2] - systemmap: {td}/boot/System.map-1.2.2 - vmlinuz: {td}/boot/vmlinuz-1.2.2 - modules: {td}/lib/modules/1.2.2 - build: {td}/lib/modules/1.2.2/../../../usr/src/linux'''.lstrip()) self.assert_kernels(Path(td))
def test_main_remove_n2_pretend(self) -> None: with self.create_layout() as td: self.assertEqual( main([ '--destructive', '-n', '2', '--pretend', '--root', td, '--debug', '--no-mount' ]), 0) self.assert_kernels(Path(td))
def test_config_file_system(self) -> None: with self.create_layout() as td: with open(Path(td) / 'eclean-kernel.rc', 'w') as f: f.write('-n "2"\n') os.environ['XDG_CONFIG_DIRS'] += f':{td}' self.assertEqual( main(['--destructive', '--root', td, '--debug', '--no-mount']), 0) self.assert_kernels(Path(td), k122=False, k124=False)
def test_main_remove_all(self) -> None: with self.create_layout() as td: self.assertEqual( main([ '--all', '--destructive', '--root', td, '--debug', '--no-mount' ]), 0) self.assert_kernels(Path(td), k121=False, k122=False, k123=False, k124=False)
def test_config_file_user(self) -> None: with self.create_layout() as td: path = Path(td) os.mkdir(path / 'system') with open(path / 'system/eclean-kernel.rc', 'w') as f: f.write('-n 1\n') with open(path / 'eclean-kernel.rc', 'w') as f: f.write('-n "2"\n') os.environ['XDG_CONFIG_DIRS'] = str(path / 'system') os.environ['XDG_CONFIG_HOME'] = td self.assertEqual( main(['--destructive', '--root', td, '--debug', '--no-mount']), 0) self.assert_kernels(Path(td), k122=False, k124=False)