From c1ee83235a4a91518d2690bf72a093d5914f11f6 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 6 May 2024 11:48:22 +0200 Subject: [PATCH 1/3] os: ensure tests pass if os-prober is not installed Signed-off-by: Olivier Gayot --- probert/tests/test_os.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/probert/tests/test_os.py b/probert/tests/test_os.py index 8632e01..07e5967 100644 --- a/probert/tests/test_os.py +++ b/probert/tests/test_os.py @@ -14,7 +14,7 @@ import subprocess from unittest import IsolatedAsyncioTestCase -from unittest.mock import patch +from unittest.mock import patch, Mock from probert.os import probe, _parse_osprober, _run_os_prober @@ -121,6 +121,7 @@ def test_winxp(self): self.assertEqual(expected, _parse_osprober(lines)) @patch('probert.os.subprocess.run') + @patch('probert.os.shutil.which', Mock()) async def test_osx_run(self, run): run.return_value.stdout = '/dev/sda4:Mac OS X:MacOSX:macosx\n' expected = { @@ -133,21 +134,25 @@ async def test_osx_run(self, run): self.assertEqual(expected, await probe()) @patch('probert.os.subprocess.run') + @patch('probert.os.shutil.which', Mock()) async def test_empty_run(self, run): run.return_value.stdout = '' self.assertEqual({}, await probe()) @patch('probert.os.subprocess.run') + @patch('probert.os.shutil.which', Mock()) async def test_none_run(self, run): run.return_value.stdout = None self.assertEqual({}, await probe()) @patch('probert.os.subprocess.run') + @patch('probert.os.shutil.which', Mock()) async def test_osprober_fail(self, run): run.side_effect = subprocess.CalledProcessError(1, 'cmd') self.assertEqual({}, await probe()) @patch('probert.os.subprocess.run') + @patch('probert.os.shutil.which', Mock()) async def test_run_once(self, run): run.return_value.stdout = '' self.assertEqual({}, await probe()) From 36357fe9fa3dfd1119416a00362696257038b8d9 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 6 May 2024 11:54:32 +0200 Subject: [PATCH 2/3] filesystem: ensure tests pass if ntfsreisze is not installed Signed-off-by: Olivier Gayot --- probert/tests/test_filesystem.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/probert/tests/test_filesystem.py b/probert/tests/test_filesystem.py index d23a0a2..518cc4b 100644 --- a/probert/tests/test_filesystem.py +++ b/probert/tests/test_filesystem.py @@ -107,18 +107,21 @@ async def test_ext4_bad_resize2fs(self, dumpe2fs, resize2fs): self.assertEqual(expected, await get_ext_sizing(self.device)) @patch('probert.filesystem.arun') + @patch('probert.filesystem.shutil.which', Mock()) async def test_ntfs_real_output(self, run): run.return_value = read_file('probert/tests/data/ntfsresize.out') expected = {'SIZE': 41939456, 'ESTIMATED_MIN_SIZE': 2613248} self.assertEqual(expected, await get_ntfs_sizing(self.device)) @patch('probert.filesystem.arun') + @patch('probert.filesystem.shutil.which', Mock()) async def test_ntfs_real_output_full(self, run): run.return_value = read_file('probert/tests/data/ntfsresize_full.out') expected = {'SIZE': 83882496, 'ESTIMATED_MIN_SIZE': 83882496} self.assertEqual(expected, await get_ntfs_sizing(self.device)) @patch('probert.filesystem.arun') + @patch('probert.filesystem.shutil.which', Mock()) async def test_ntfs_simple_output(self, run): run.return_value = ''' Current volume size: 100000000 bytes (100 MB) From c2f70c553f00c0301de0464e51ee76ae52fddcd8 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 6 May 2024 12:12:13 +0200 Subject: [PATCH 3/3] Only require test dependencies when building without nocheck Signed-off-by: Olivier Gayot --- debian/control | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/debian/control b/debian/control index 64a78b8..d666997 100644 --- a/debian/control +++ b/debian/control @@ -8,12 +8,12 @@ Build-Depends: debhelper-compat (= 13), libnl-route-3-dev, pkg-config, python3-all-dev, - python3-coverage, - python3-flake8, - python3-jsonschema, - python3-nose, - python3-parameterized, - python3-pyudev, + python3-coverage , + python3-flake8 , + python3-jsonschema , + python3-nose , + python3-parameterized , + python3-pyudev , python3-setuptools, Standards-Version: 4.5.0 Homepage: https://github.com/canonical/probert