# Copyright (C) Stichting Deltares 2021. All rights reserved. # # This file is part of the Dam Python Interface. # # The Dam Python Interface is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # All names, logos, and references to "Deltares" are registered trademarks of # Stichting Deltares and remain full property of Stichting Deltares at all times. # All rights reserved. from dampythoninterface.location import ( DesignScenario, Location, General, WaternetOptions, PhreaticLineCreationMethodType, IntrusionVerticalWaterPressureType, DikeSoilScenarioType, ) import pytest from .utils import TestUtils from pathlib import Path from lxml import etree class TestLocation: @pytest.mark.integrationtest def test_serialize_location(self): # define stability options design_scenario_1 = DesignScenario( Id="1", RiverLevel=3.2, PlLineOffsetBelowDikeTopAtRiver=1.1, PlLineOffsetBelowDikeTopAtPolder=2.1, PlLineOffsetBelowShoulderBaseInside=3.1, PlLineOffsetBelowDikeToeAtPolder=4.1, UpliftCriterionStability=5, UpliftCriterionPiping=0, RequiredSafetyFactorStabilityInnerSlope=1.6, RequiredSafetyFactorStabilityOuterSlope=1.5, RequiredSafetyFactorPiping=2.1, PolderLevel=4, ) design_scenario_2 = DesignScenario( Id="2", RiverLevel=2.2, PlLineOffsetBelowDikeTopAtRiver=2.1, PlLineOffsetBelowDikeTopAtPolder=1.1, PlLineOffsetBelowShoulderBaseInside=5.1, PlLineOffsetBelowDikeToeAtPolder=6.1, UpliftCriterionStability=1, UpliftCriterionPiping=2, RequiredSafetyFactorStabilityInnerSlope=2.6, RequiredSafetyFactorStabilityOuterSlope=2.5, RequiredSafetyFactorPiping=1.1, PolderLevel=6, ) general_settings = General( Description="General settings for the project", HeadPL2=0, HeadPL3=1, HeadPL4=3, ) waternet_options = WaternetOptions( PhreaticLineCreationMethod=PhreaticLineCreationMethodType.ExpertKnowledgeRRD, DampingFactorPl3=0, DampingFactorPl4=0, PenetrationLength=0, SlopeDampingFactor=0, IntrusionVerticalWaterPressure=IntrusionVerticalWaterPressureType.Standard, DikeSoilScenario=DikeSoilScenarioType.ClayDikeOnClay, ) # define location model_location = Location( SurfaceLineName="Line 1", SegmentName="Input segment", Name="Location of dike", DikeEmbankmentMaterial="clay", XSoilGeometry2DOrigin=4, DesignScenarios=[design_scenario_1, design_scenario_2], General=general_settings, WaternetOptions=waternet_options, ) # check initial expectations assert model_location.Name == "Location of dike" # run test root = model_location.serialize() # test output xml_output = Path( TestUtils.get_output_test_data_dir(""), "test_serialize_location.xml" ) tree = etree.ElementTree(root) tree.write(str(xml_output), pretty_print=True) # get template file xml_test_data = Path( TestUtils.get_test_data_dir("", "test_data"), "test_serialize_location.xml", ) # Line by line comparison for output_file, test_file in zip(open(xml_output), open(xml_test_data)): assert output_file.strip() == test_file.strip()