add some tests for pe helper classes

main
svalouch 5 years ago
parent 35c0a1df7e
commit 42df36a2c3

@ -0,0 +1,80 @@
import pytest
from simplezfs.pe_helper import ExternalPEHelper, PEHelperBase, SudoPEHelper
class TestPEHelperBase:
def test_repr(self):
pehb = PEHelperBase()
assert 'PEHelperBase' in str(pehb)
def test_not_implemented(self):
pehb = PEHelperBase()
with pytest.raises(NotImplementedError):
pehb.zfs_mount('test')
with pytest.raises(NotImplementedError):
pehb.zfs_set_mountpoint('test', '/test')
class TestExternalPEHelper:
def test_repr(self):
eph = ExternalPEHelper('/bin/true')
assert 'ExternalPEHelper' in str(eph)
assert '/bin/true' in str(eph)
# ########################################################################
def test_get_executable(self):
eph = ExternalPEHelper('/bin/true')
assert eph.executable == '/bin/true'
def test_set_executable(self):
eph = ExternalPEHelper('/bin/false')
assert eph.executable == '/bin/false'
eph.executable = '/bin/true'
assert eph.executable == '/bin/true'
def test_set_executable_not_found_ctor(self):
with pytest.raises(FileNotFoundError) as e:
ExternalPEHelper('/file/does/not/exist')
assert 'No such file or directory' in str(e.value)
def test_set_executable_not_found_property(self):
eph = ExternalPEHelper('/bin/true')
with pytest.raises(FileNotFoundError) as e:
eph.executable = '/file/does/not/exist'
assert 'No such file or directory' in str(e.value)
def test_set_executable_directory_ctor(self):
with pytest.raises(FileNotFoundError) as e:
ExternalPEHelper('/')
assert 'must be a file' in str(e.value)
def test_set_executable_directory_property(self):
eph = ExternalPEHelper('/bin/true')
with pytest.raises(FileNotFoundError) as e:
eph.executable = '/'
assert 'must be a file' in str(e.value)
def test_set_executable_nonexecutable_ctor(self):
with pytest.raises(FileNotFoundError) as e:
ExternalPEHelper('/etc/hosts')
assert 'must be executable' in str(e.value)
def test_set_executable_nonexecutable_property(self):
eph = ExternalPEHelper('/bin/true')
with pytest.raises(FileNotFoundError) as e:
eph.executable = '/etc/hosts'
assert 'must be executable' in str(e.value)
class TestSudoPEHelper:
def test_repr(self):
sph = SudoPEHelper()
assert 'SudoPEHelper' in str(sph)
assert 'sudo' in str(sph)

@ -7,6 +7,7 @@ from unittest.mock import patch
import pytest # type: ignore import pytest # type: ignore
from simplezfs.exceptions import ValidationError from simplezfs.exceptions import ValidationError
from simplezfs.pe_helper import PEHelperBase
from simplezfs.types import Dataset, DatasetType from simplezfs.types import Dataset, DatasetType
from simplezfs.zfs import ZFS, get_zfs from simplezfs.zfs import ZFS, get_zfs
from simplezfs.zfs_cli import ZFSCli from simplezfs.zfs_cli import ZFSCli
@ -29,6 +30,19 @@ class TestZFS:
########################################################################## ##########################################################################
def test_get_pe_helper_default(self):
zfs = ZFS()
assert zfs.pe_helper is None
def test_get_pe_helper_set_valid(self):
zfs = ZFS()
assert zfs.pe_helper is None
zfs.pe_helper = PEHelperBase()
assert zfs.pe_helper is not None
assert isinstance(zfs.pe_helper, PEHelperBase)
##########################################################################
def test_get_property_notimplemented(self): def test_get_property_notimplemented(self):
zfs = ZFS() zfs = ZFS()
with pytest.raises(NotImplementedError): with pytest.raises(NotImplementedError):

Loading…
Cancel
Save