# 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.stability_parameters import ( StabilityParameters, SearchMethodType, GridDeterminationType, BishopTangentLinesDefinitionType, UpliftVanTangentLinesDefinitionType, ) from .utils import TestUtils import pytest from pathlib import Path from lxml import etree class TestStabiltyParameters: @pytest.mark.unittest def test_soil_can_be_initialized(self): # initialize the stabilty parameters class test_stabilty_parameters = StabilityParameters( SearchMethod=SearchMethodType.GeneticAlgorithm, GridDetermination=GridDeterminationType.Specified, ) # check expectations assert ( test_stabilty_parameters.SearchMethod == SearchMethodType.GeneticAlgorithm ) assert ( test_stabilty_parameters.GridDetermination == GridDeterminationType.Specified ) @pytest.mark.unittest def test_serialize(self): # initialize the stabilty parameters class test_stabilty_parameters = StabilityParameters( SearchMethod=SearchMethodType.Calculationgrid, GridDetermination=GridDeterminationType.Automatic, BishopTangentLinesDefinition=BishopTangentLinesDefinitionType.OnBoundaryLines, BishopTangentLinesDistance=0.25, BishopGridVerticalPointsCount=10, BishopGridVerticalPointsDistance=2.5, BishopGridHorizontalPointsCount=10, BishopGridHorizontalPointsDistance=2.5, UpliftVanGridLeftVerticalPointsCount=36, UpliftVanGridLeftVerticalPointsDistance=2, UpliftVanGridLeftHorizontalPointsCount=14, UpliftVanGridLeftHorizontalPointsDistance=2, UpliftVanGridRightVerticalPointsCount=3, UpliftVanGridRightVerticalPointsDistance=2, UpliftVanGridRightHorizontalPointsCount=6, UpliftVanGridRightHorizontalPointsDistance=2, UpliftVanTangentLinesDefinition=UpliftVanTangentLinesDefinitionType.OnBoundaryLines, UpliftVanTangentLinesDistance=0.25, ) # run test root = test_stabilty_parameters.serialize() # test output xml_output = Path( TestUtils.get_output_test_data_dir(""), "test_stabilty_parameters.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_stabilty_parameters.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()