Skip to content

Commit

Permalink
Removed setters & fixed tests (#107)
Browse files Browse the repository at this point in the history
This fixes #104. Removed the newly introduced filename setters and
amended docstrings to indicate the properties are read-only.
Additionally amended the tests to check the properties ARE read only
instead of checking that they were write as well.
  • Loading branch information
jgd10 authored Feb 1, 2022
1 parent abc795f commit 61c5d7e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 44 deletions.
6 changes: 1 addition & 5 deletions ansys/mapdl/reader/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,14 @@ def __init__(self, filename, read_parameters=False,

@property
def filename(self) -> str:
"""String form of the filename. Accepts ``pathlib.Path`` and string objects when set."""
"""String form of the filename. This property is read-only."""
return str(self._filename)

@property
def pathlib_filename(self) -> pathlib.Path:
"""Return the ``pathlib.Path`` version of the filename. This property can not be set."""
return self._filename

@filename.setter
def filename(self, value: Union[str, pathlib.Path]):
self._filename = pathlib.Path(value)

@property
def raw(self): # pragma: no cover
raise AttributeError('The `raw` attribute has been depreciated. Access'
Expand Down
6 changes: 1 addition & 5 deletions ansys/mapdl/reader/emat.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,14 @@ def __init__(self, filename):

@property
def filename(self):
"""String form of the filename. Accepts ``pathlib.Path`` and string objects when set."""
"""String form of the filename. This property is read-only."""
return str(self._filename)

@property
def pathlib_filename(self):
"""Return the ``pathlib.Path`` version of the filename. This property can not be set."""
return self._filename

@filename.setter
def filename(self, value):
self._filename = pathlib.Path(value)

def read_header(self):
"""Read standard emat file header"""
with open(self.pathlib_filename, 'rb') as f:
Expand Down
6 changes: 1 addition & 5 deletions ansys/mapdl/reader/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,14 @@ def __init__(self, filename: Union[str, pathlib.Path]):

@property
def filename(self):
"""String form of the filename. Accepts ``pathlib.Path`` and string objects when set."""
"""String form of the filename. This property is read-only."""
return str(self._filename)

@property
def pathlib_filename(self):
"""Return the ``pathlib.Path`` version of the filename. This property can not be set."""
return self._filename

@filename.setter
def filename(self, value):
self._filename = pathlib.Path(value)

@property
def k(self):
"""Stiffness Matrix corresponding to sorted DOF.
Expand Down
6 changes: 1 addition & 5 deletions ansys/mapdl/reader/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,14 @@ def __init__(self, filename, read_mesh=True, parse_vtk=True, **kwargs):

@property
def filename(self) -> str:
"""String form of the filename. Accepts ``pathlib.Path`` and string objects when set."""
"""String form of the filename. This property is read-only."""
return str(self._filename)

@property
def pathlib_filename(self) -> pathlib.Path:
"""Return the ``pathlib.Path`` version of the filename. This property can not be set."""
return self._filename

@filename.setter
def filename(self, value: Union[str, pathlib.Path]):
self._filename = pathlib.Path(value)

@property
def mesh(self):
"""Mesh from result file.
Expand Down
10 changes: 4 additions & 6 deletions tests/archive/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,9 @@ def test_filename_property_is_string(self, pathlib_archive):
assert isinstance(a.filename, str)

def test_filename_setter_pathlib(self, pathlib_archive):
pathlib_archive.filename = pathlib.Path('dummy2')
assert isinstance(pathlib_archive.filename, str)
assert isinstance(pathlib_archive.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
pathlib_archive.filename = pathlib.Path('dummy2')

def test_filename_setter_string(self, pathlib_archive):
pathlib_archive.filename = 'dummy2'
assert isinstance(pathlib_archive.filename, str)
assert isinstance(pathlib_archive.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
pathlib_archive.filename = 'dummy2'
11 changes: 5 additions & 6 deletions tests/test_emat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def test_filename_property_is_string(self, emat_pathlib):
assert isinstance(emat_pathlib.filename, str)

def test_filename_setter_pathlib(self, emat_pathlib):
emat_pathlib.filename = pathlib.Path('dummy2')
assert isinstance(emat_pathlib.filename, str)
assert isinstance(emat_pathlib.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
emat_pathlib.filename = pathlib.Path('dummy2')

def test_filename_setter_string(self, emat_pathlib):
emat_pathlib.filename = 'dummy2'
assert isinstance(emat_pathlib.filename, str)
assert isinstance(emat_pathlib.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
emat_pathlib.filename = 'dummy2'

10 changes: 4 additions & 6 deletions tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ def test_filename_property_is_string(self, sparse_full_pathlib_full_file):
assert isinstance(sparse_full_pathlib_full_file.filename, str)

def test_filename_setter_pathlib(self, sparse_full_pathlib_full_file):
sparse_full_pathlib_full_file.filename = pathlib.Path('dummy2')
assert isinstance(sparse_full_pathlib_full_file.filename, str)
assert isinstance(sparse_full_pathlib_full_file.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
sparse_full_pathlib_full_file.filename = pathlib.Path('dummy2')

def test_filename_setter_string(self, sparse_full_pathlib_full_file):
sparse_full_pathlib_full_file.filename = 'dummy2'
assert isinstance(sparse_full_pathlib_full_file.filename, str)
assert isinstance(sparse_full_pathlib_full_file.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
sparse_full_pathlib_full_file.filename = 'dummy2'
10 changes: 4 additions & 6 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,15 @@ def test_filename_property_is_string(self, pathlib_result):
@pytest.mark.skipif(not os.path.isfile(temperature_rst),
reason="Requires example files")
def test_filename_setter_pathlib(self, pathlib_result):
pathlib_result.filename = pathlib.Path('dummy2')
assert isinstance(pathlib_result.filename, str)
assert isinstance(pathlib_result.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
pathlib_result.filename = pathlib.Path('dummy2')

@skip_plotting
@pytest.mark.skipif(not os.path.isfile(temperature_rst),
reason="Requires example files")
def test_filename_setter_string(self, pathlib_result):
pathlib_result.filename = 'dummy2'
assert isinstance(pathlib_result.filename, str)
assert isinstance(pathlib_result.pathlib_filename, pathlib.Path)
with pytest.raises(AttributeError):
pathlib_result.filename = 'dummy2'


def test_rst_node_components(hex_rst):
Expand Down

0 comments on commit 61c5d7e

Please sign in to comment.