# 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.soilprofile1D import ( SoilProfile1D, Layer1D, WaterpressureInterpolationModelType, ) from .utils import TestUtils import pytest from pathlib import Path from lxml import etree class TestSoilProfile1D: def define_soil_profile(self) -> SoilProfile1D: # first define the soil layers layer_1 = Layer1D( Name="L0", SoilName="Dijkmateriaal", TopLevel=10, IsAquifer=False, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) layer_2 = Layer1D( Name="L1", SoilName="Deklaag_klei", TopLevel=0, IsAquifer=False, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) layer_3 = Layer1D( Name="L2", SoilName="wl_zand1", TopLevel=-2, IsAquifer=True, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) soil_profile = SoilProfile1D( Name="soilprofile_01", BottomLevel=-10, Layers1D=[layer_1, layer_2, layer_3] ) return soil_profile @pytest.mark.unittest def test_soil_profile_can_be_initialized(self): soil_profile = self.define_soil_profile() # test expectations assert soil_profile.Name == "soilprofile_01" assert len(soil_profile.Layers1D) == 3 assert soil_profile.Layers1D[-1].SoilName == "wl_zand1" @pytest.mark.unittest def test_serialize(self): # initialize the stabilty parameters class soil_profile = self.define_soil_profile() # run test root = soil_profile.serialize() # test output xml_output = Path( TestUtils.get_output_test_data_dir(""), "test_soil_profile.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_soil_profile.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()