Skip to content

Commit

Permalink
Bump version 0.13.1 (#1575)
Browse files Browse the repository at this point in the history
* Case Reader to parse numerical values with units. (#1570)

* Case Reader to parse numerical values with units.

* Updated logic.

* Update value.

* endswith instead of suffixes.

* Update endswith -> Path-match

* Improve error handling.

* Update test with correct error type.

---------

Co-authored-by: Your Name <[email protected]>

* Bump version 0.13.1

---------

Co-authored-by: Prithwish Mukherjee <[email protected]>
Co-authored-by: Your Name <[email protected]>
  • Loading branch information
3 people authored May 4, 2023
1 parent 3ea9735 commit d469fa7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

# major, minor, patch
version_info = 0, 13, 0
version_info = 0, 13, 1

# Nice string for the version
__version__ = ".".join(map(str, version_info))
31 changes: 20 additions & 11 deletions src/ansys/fluent/core/filereader/case_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self, raw_data):
self.name = v.strip('"')
elif k == "definition":
self.value = v.strip('"')
if "[" in self.value:
sep_index = self.value.index("[")
if not self.value[sep_index - 1] == " ":
self.value = "".join(
(self.value[:sep_index], " ", self.value[sep_index:])
)

@property
def units(self) -> str:
Expand Down Expand Up @@ -183,32 +189,35 @@ def __init__(self, case_filepath: str = None, project_filepath: str = None):
raise FileNotFoundError(
"Please provide a valid fluent project file path"
)

try:
if "".join(Path(case_filepath).suffixes) == ".cas.h5":
if Path(case_filepath).match("*.cas.h5"):
file = h5py.File(case_filepath)
settings = file["settings"]
rpvars = settings["Rampant Variables"][0]
rp_vars_str = rpvars.decode()
elif Path(case_filepath).suffix == ".cas":
elif Path(case_filepath).match("*.cas"):
with open(case_filepath, "rb") as file:
rp_vars_str = file.read()
rp_vars_str = _get_processed_string(rp_vars_str)
elif "".join(Path(case_filepath).suffixes) == ".cas.gz":
elif Path(case_filepath).match("*.cas.gz"):
with gzip.open(case_filepath, "rb") as file:
rp_vars_str = file.read()
rp_vars_str = _get_processed_string(rp_vars_str)
else:
raise RuntimeError()
error_message = (
"Could not read case file. "
"Only valid Case files (.h5, .cas, .cas.gz) can be read. "
)
raise RuntimeError(error_message)

except FileNotFoundError as e:
raise RuntimeError(f"The case file {case_filepath} cannot be found.") from e
raise FileNotFoundError(
f"The case file {case_filepath} cannot be found."
) from e

except OSError:
error_message = (
"Could not read case file. "
"Only valid Case files (.h5, .cas, .cas.gz) can be read. "
)
raise RuntimeError(error_message)
except OSError as e:
raise OSError(f"Error while reading case file {case_filepath}") from e

except BaseException as e:
raise RuntimeError(f"Could not read case file {case_filepath}") from e
Expand Down
9 changes: 8 additions & 1 deletion tests/test_casereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_processed_string():


def test_casereader_no_file():
with pytest.raises(RuntimeError):
with pytest.raises(FileNotFoundError):
call_casereader("no_file.cas.h5")


Expand Down Expand Up @@ -224,6 +224,13 @@ def test_case_reader_input_parameter():
assert momentum.numeric_value == 12.4
assert momentum.value == "12.4 [kg m s^-1]"

velocity = InputParameter(raw_data=(("name", "v"), ("definition", "2[m/s]")))

assert velocity.name == "v"
assert velocity.units == "m/s"
assert velocity.numeric_value == 2
assert velocity.value == "2 [m/s]"


def test_lispy_for_multiline_string():
assert lispy.parse('(define x "abc\ndef")') == ["define", "x", '"abc\ndef"']

0 comments on commit d469fa7

Please sign in to comment.