Skip to content

Commit

Permalink
in common class
Browse files Browse the repository at this point in the history
  • Loading branch information
dbungert committed Sep 12, 2023
1 parent f997d66 commit 6a00322
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
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)
10 changes: 6 additions & 4 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,9 +61,9 @@ async def test_expected_output_vg(self):
assert expected == await get_swap_sizing(device)


@patch('probert.filesystem.shutil.which', new=Mock(return_value='/bin/false'))
class TestFilesystem(IsolatedAsyncioTestCase):
class TestFilesystem(ProbertTestCase):
def setUp(self):
super().setUp()
self.device = Mock()
self.device.device_node = random_string()

Expand Down Expand Up @@ -198,10 +199,11 @@ async def test_get_device_filesystem_sizing_ext4_no_min(self):
self.assertEqual(expected, actual)


@patch('probert.filesystem.shutil.which', new=Mock(return_value=None))
class TestFilesystemToolNotFound(IsolatedAsyncioTestCase):
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))
Expand Down
14 changes: 8 additions & 6 deletions probert/tests/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

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


@patch('probert.filesystem.shutil.which', new=Mock(return_value='/bin/false'))
class TestOsProber(IsolatedAsyncioTestCase):
class TestOsProber(ProbertTestCase):
def tearDown(self):
_run_os_prober.cache_clear()

Expand Down Expand Up @@ -157,7 +156,10 @@ async def test_run_once(self, run):
run.assert_called_once()


@patch('probert.filesystem.shutil.which', new=Mock(return_value=None))
class TestOsProberNotFound(IsolatedAsyncioTestCase):
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())

0 comments on commit 6a00322

Please sign in to comment.