# 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.segment import ( Segment, SoilGeometryProbabilityElement, SoilProfileTypeClass, SegmentFailureMechanismTypeClass, ) from .utils import TestUtils import pytest from pathlib import Path from lxml import etree class TestSegment: def define_segment(self) -> Segment: # first define the soil layers profile_1 = SoilGeometryProbabilityElement( SoilProfileName="soilprofile_01", SoilProfileType=SoilProfileTypeClass.ProfileType1D, Probability=1, SegmentFailureMechanismType=SegmentFailureMechanismTypeClass.Stability, ) profile_2 = SoilGeometryProbabilityElement( SoilProfileName="soilprofile_01", SoilProfileType=SoilProfileTypeClass.ProfileType1D, Probability=1, SegmentFailureMechanismType=SegmentFailureMechanismTypeClass.Piping, ) return Segment( Name="Test segment", SoilGeometryProbability=[profile_1, profile_2] ) @pytest.mark.unittest def test_if_segment_can_be_initialized(self): segment = self.define_segment() # test expectations assert segment.Name == "Test segment" assert len(segment.SoilGeometryProbability) == 2 assert segment.SoilGeometryProbability[-1].SoilProfileName == "soilprofile_01" @pytest.mark.unittest def test_serialize(self): # initialize the stabilty parameters class segment = self.define_segment() # run test root = segment.serialize() # test output xml_output = Path(TestUtils.get_output_test_data_dir(""), "test_segment.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_segment.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()