Skip to content

Commit

Permalink
Fix form parsing edge-case for critical pressure (#18)
Browse files Browse the repository at this point in the history
* Better handling of non-Pc case

* Improve tests for non-Pc pressure case
  • Loading branch information
ml-evs authored Oct 12, 2023
1 parent c30f0f3 commit 447b9c5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/PASCal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _set_named_coeffs(self):
[d[2] if len(d) > 2 else "n/a" for d in sigmas], dtype=object
)
self.named_coefficients["PcCoef"] = np.array(
[0.0, 0.0, self.options.pc_val]
[0.0, 0.0, self.options.pc_val if self.options.pc_val else 0.0]
)
self.named_coefficients["CalPress"] = np.zeros(
(len(self.volume_fits), len(self.cell_volumes))
Expand Down
9 changes: 7 additions & 2 deletions src/PASCal/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ def from_dict(options: Dict[str, Any]) -> "Options":

if options.get("data_type"):
options["data_type"] = PASCalDataType[options["data_type"].upper()]
if options.get("pc_val"):
options["pc_val"] = float(options["pc_val"])
if options.get("pc_val") is not None:
if not options.get("pc_val"):
options["pc_val"] = None
else:
options["pc_val"] = float(options["pc_val"])
if options.get("pc_val") is None:
options["use_pc"] = False
if options.get("deg_poly_strain"):
options["deg_poly_strain"] = int(options["deg_poly_strain"])
if options.get("deg_poly_vol"):
Expand Down
45 changes: 45 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,33 @@ def test_q_sample_data(
), "Volumes table failed"


def test_p_no_pc_sample_data(
client,
sample_p,
parser,
):
post_parameters = {
"DataType": "Pressure",
"EulerianStrain": "True",
"FiniteStrain": "True",
"DegPolyCap": "",
"DegPolyVol": "",
"UsePc": "False",
"PcVal": "",
"data": sample_p,
}

response = client.post("/output", data=post_parameters)
assert response.status_code == 200

html_response = [d for d in response.response]
assert len(html_response) == 1

soup = parser(html_response[0])
tables = soup.find_all("table")
assert len(tables) == 7


def test_parse_options():
from PASCal.options import Options, PASCalDataType

Expand All @@ -227,3 +254,21 @@ def test_parse_options():
assert options.deg_poly_strain == 12
assert options.deg_poly_vol == 10
assert not options.finite_strain

form_example = {
"DataType": "Temperature",
"UsePc": "False",
"PcVal": "",
"EulerianStrain": "True",
"DegPolyVol": "10",
"DegPolyCap": "12",
"FiniteStrain": "False",
}
options = Options.from_form(form_example)
assert options.data_type == PASCalDataType.TEMPERATURE
assert options.use_pc is False
assert options.pc_val is None
assert options.eulerian_strain
assert options.deg_poly_strain == 12
assert options.deg_poly_vol == 10
assert not options.finite_strain

0 comments on commit 447b9c5

Please sign in to comment.