# 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.soil import ShearStrengthModelType, Soil, DilatancyTypeModel from .utils import TestUtils import pytest from pathlib import Path from lxml import etree class TestSoil: @pytest.mark.unittest def test_soil_can_be_initialized(self): # initialize the soil model class test_soil = Soil( Name="new soil", AbovePhreaticLevel=18, BelowPhreaticLevel=20, ) # check expectations assert test_soil.Name == "new soil" assert test_soil.AbovePhreaticLevel == 18 assert test_soil.BelowPhreaticLevel == 20 @pytest.mark.unittest def test_serialize_soil(self): # initialize the soil model class test_soil = Soil( Name="Dijkmateriaal", BeddingAngle=37, DiameterD70=0.0002, PermeabKx=0.0004, WhitesConstant=0.25, AbovePhreaticLevel=17, BelowPhreaticLevel=17, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0.5, FrictionAngle=22, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) # run test root = test_soil.serialize_soil() # test output xml_output = Path( TestUtils.get_output_test_data_dir(""), "test_serialize_soil.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.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()