Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions probert/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import shutil # noqa: F401
from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch


class ProbertTestCase(IsolatedAsyncioTestCase):
def setUp(self):
which = patch("shutil.which")
self.m_which = which.start()
self.m_which.return_value = '/bin/false'
self.addCleanup(which.stop)
23 changes: 13 additions & 10 deletions probert/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_swap_sizing,
get_device_filesystem,
)
from probert.tests import ProbertTestCase


def read_file(filename):
Expand Down Expand Up @@ -60,8 +61,9 @@ async def test_expected_output_vg(self):
assert expected == await get_swap_sizing(device)


class TestFilesystem(IsolatedAsyncioTestCase):
class TestFilesystem(ProbertTestCase):
def setUp(self):
super().setUp()
self.device = Mock()
self.device.device_node = random_string()

Expand Down Expand Up @@ -196,17 +198,18 @@ async def test_get_device_filesystem_sizing_ext4_no_min(self):
actual = await get_device_filesystem(self.device, True)
self.assertEqual(expected, actual)

@patch('probert.filesystem.shutil.which')
async def test_ntfsresize_not_found(self, which):
which.return_value = None

class TestFilesystemToolNotFound(ProbertTestCase):
def setUp(self):
super().setUp()
self.device = Mock()
self.m_which.return_value = None

async def test_ntfsresize_not_found(self):
self.assertEqual(None, await get_ntfs_sizing(self.device))

@patch('probert.filesystem.shutil.which')
async def test_dumpe2fs_not_found(self, which):
which.return_value = None
async def test_dumpe2fs_not_found(self):
self.assertEqual(None, await get_dumpe2fs_info(self.device))

@patch('probert.filesystem.shutil.which')
async def test_resize2fs_not_found(self, which):
which.return_value = None
async def test_resize2fs_not_found(self):
self.assertEqual(None, await get_resize2fs_info(self.device))
13 changes: 11 additions & 2 deletions probert/tests/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import subprocess
from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch

from probert.os import probe, _parse_osprober, _run_os_prober
from probert.tests import ProbertTestCase


class TestOsProber(IsolatedAsyncioTestCase):
class TestOsProber(ProbertTestCase):
def tearDown(self):
_run_os_prober.cache_clear()

Expand Down Expand Up @@ -154,3 +154,12 @@ async def test_run_once(self, run):
self.assertEqual({}, await probe())
self.assertEqual({}, await probe())
run.assert_called_once()


class TestOsProberNotFound(ProbertTestCase):
def setUp(self):
super().setUp()
self.m_which.return_value = None

async def test_os_prober_not_found(self):
self.assertEqual(None, _run_os_prober())