|
27 | 27 | recursive_converter, |
28 | 28 | ) |
29 | 29 | from hydrolib.tools.extforce_convert.mdu_parser import MDUParser |
| 30 | +from hydrolib.tools.extforce_convert.utils import UnSupportedQuantitiesError |
30 | 31 |
|
31 | 32 |
|
32 | 33 | class TestExtOldToNewFromMDU: |
@@ -529,6 +530,84 @@ def test_externalforcingconverter_os_style_converted_to_path_style( |
529 | 530 | initial_file = tmp_path / "new-initial-conditions.ini" |
530 | 531 | assert setup_absolute_path_files["raw_poly_file"] in initial_file.read_text() |
531 | 532 |
|
| 533 | + @pytest.fixture |
| 534 | + def old_model(self) -> Dict[str, Any]: |
| 535 | + return { |
| 536 | + "forcing": [ |
| 537 | + { |
| 538 | + "quantity": "InternalTidesFrictionCoefficient", |
| 539 | + "filename": "file.xyz", |
| 540 | + "filetype": 7, |
| 541 | + "method": 1, |
| 542 | + "operand": "O", |
| 543 | + }, |
| 544 | + { |
| 545 | + "quantity": "unsupported_quantity", |
| 546 | + "filename": "file2.xyz", |
| 547 | + "filetype": 7, |
| 548 | + "method": 4, |
| 549 | + "operand": "O", |
| 550 | + "value": 0.0125, |
| 551 | + }, |
| 552 | + ] |
| 553 | + } |
| 554 | + |
| 555 | + @pytest.mark.parametrize( |
| 556 | + "unsupported_quantity", |
| 557 | + ["waveperiod", "waqfunctionTau", "waqfunctionradsurfave"], |
| 558 | + ids=["quantity", "prefix_capitalized", "prefix_lowercase"], |
| 559 | + ) |
| 560 | + def test_debug_unsupported_quantities_conversion( |
| 561 | + self, old_model, unsupported_quantity: str |
| 562 | + ): |
| 563 | + old_model["forcing"][1]["quantity"] = unsupported_quantity |
| 564 | + ext_old_model = ExtOldModel(**old_model) |
| 565 | + ext_old_model.filepath = Path("tests/data/input/mock_file.ext") |
| 566 | + converter = ExternalForcingConverter(extold_model=ext_old_model, debug=True) |
| 567 | + converter.update() |
| 568 | + |
| 569 | + assert converter.un_supported_quantities == {unsupported_quantity.lower()} |
| 570 | + assert ext_old_model.forcing[0].quantity == unsupported_quantity |
| 571 | + |
| 572 | + @pytest.mark.parametrize( |
| 573 | + "unsupported_quantity", |
| 574 | + ["waveperiod", "waqfunctionTau", "waqfunctionradsurfave"], |
| 575 | + ids=["quantity", "prefix_capitalized", "prefix_lowercase"], |
| 576 | + ) |
| 577 | + def test_no_debug_unsupported_quantities_conversion( |
| 578 | + self, old_model, unsupported_quantity: str |
| 579 | + ): |
| 580 | + old_model["forcing"][1]["quantity"] = unsupported_quantity |
| 581 | + ext_old_model = ExtOldModel(**old_model) |
| 582 | + ext_old_model.filepath = Path("tests/data/input/mock_file.ext") |
| 583 | + with pytest.raises(UnSupportedQuantitiesError) as error: |
| 584 | + ExternalForcingConverter(extold_model=ext_old_model, debug=False) |
| 585 | + quantity = {unsupported_quantity.lower()} |
| 586 | + assert ( |
| 587 | + f"The following quantities are not supported by the converter yet: {quantity}" |
| 588 | + in str(error) |
| 589 | + ) |
| 590 | + |
| 591 | + @pytest.mark.parametrize( |
| 592 | + "unsupported_quantity", |
| 593 | + ["waveperiod", "waqfunctionTau", "waqfunctionradsurfave"], |
| 594 | + ids=["quantity", "prefix_capitalized", "prefix_lowercase"], |
| 595 | + ) |
| 596 | + def test_debug_unsupported_quantities_save( |
| 597 | + self, old_model, tmp_path: Path, unsupported_quantity: str |
| 598 | + ): |
| 599 | + old_model["forcing"][1]["quantity"] = unsupported_quantity |
| 600 | + ext_old_model = ExtOldModel(**old_model) |
| 601 | + ext_old_model.filepath = tmp_path / "mock_file.ext" |
| 602 | + converter = ExternalForcingConverter(extold_model=ext_old_model, debug=True) |
| 603 | + converter.update() |
| 604 | + with patch( |
| 605 | + "hydrolib.tools.extforce_convert.main_converter.ExtOldModel.save" |
| 606 | + ) as mock_save: |
| 607 | + converter.save() |
| 608 | + mock_save.assert_called_once() |
| 609 | + assert converter.un_supported_quantities == {unsupported_quantity.lower()} |
| 610 | + |
532 | 611 |
|
533 | 612 | class TestUpdate: |
534 | 613 |
|
|
0 commit comments