예제 #1
0
 def test_given_wrong_numcoordinates_raises_assertionerror(self):
     with pytest.raises(AssertionError) as exc_mssg:
         Lateral.validate_coordinates(field_value=[42, 24],
                                      values=dict(numcoordinates=1))
     assert (
         str(exc_mssg.value) ==
         "Number of coordinates given (2) not matching the numCoordinates value 1."
     )
예제 #2
0
 def test_given_wrong_location_type_raises_valueerror(
         self, value: str):
     with pytest.raises(ValueError) as exc_mssg:
         Lateral.validate_location_type(value)
     assert (
         str(exc_mssg.value) ==
         f"Value given ({value}) not accepted, should be one of: 1d, 2d, all"
     )
예제 #3
0
 def test_given_no_numcoordinates_raises_valueerror(self):
     with pytest.raises(ValueError) as exc_mssg:
         Lateral.validate_coordinates(
             field_value=[42, 24], values=dict(numcoordinates=None))
     assert (
         str(exc_mssg.value) ==
         "numCoordinates should be given when providing xCoordinates or yCoordinates."
     )
예제 #4
0
 def test_given_no_values_raises_valueerror(self,
                                            dict_values: dict):
     with pytest.raises(ValueError) as exc_err:
         Lateral.validate_location_dependencies(values=dict_values)
     assert (
         str(exc_err.value) ==
         "Either nodeId, branchId (with chainage) or numCoordinates (with xCoordinates and yCoordinates) are required."
     )
예제 #5
0
 def test_given_branchid_and_no_chainage_raises_valueerror(self):
     with pytest.raises(ValueError) as exc_err:
         Lateral.validate_location_dependencies(
             dict(
                 nodeid=None,
                 branchid="aBranchId",
                 chainage=None,
             ))
     assert (str(
         exc_err.value
     ) == "Chainage should be provided when branchId is specified.")
예제 #6
0
 def test_given_1d_args_and_location_type_other_then_raises_valueerror(
         self, dict_values: dict):
     test_values = dict(
         numcoordinates=2,
         xcoordinates=[42, 24],
         ycoordinates=[24, 42],
         locationtype="wrongType",
     )
     test_dict = {**dict_values, **test_values}
     with pytest.raises(ValueError) as exc_err:
         Lateral.validate_location_dependencies(test_dict)
     assert (
         str(exc_err.value) ==
         "LocationType should be 1d when nodeId (or branchId and chainage) is specified."
     )
예제 #7
0
 def test_given_numcoords_but_missing_coordinates(
         self, missing_coordinates: str):
     test_dict = dict(
         nodeid=None,
         branchid=None,
         chainage=None,
         numcoordinates=2,
         xcoordinates=[42, 24],
         ycoordinates=[24, 42],
     )
     test_dict[missing_coordinates.lower()] = None
     with pytest.raises(ValueError) as exc_error:
         Lateral.validate_location_dependencies(test_dict)
     assert str(exc_error.value
                ) == f"{missing_coordinates} should be given."
예제 #8
0
            def test_given_valid_args_validates_locationtype(
                    self, location_dict: str):
                # 1. Define test data.
                default_values = dict(
                    id="42",
                    discharge="fDischarge",
                    numcoordinates=2,
                )
                lateral_dict = {**default_values, **location_dict}
                # 2. Run test.
                lateral_cls = Lateral(**lateral_dict)

                # 3. Validate expectations.
                assert isinstance(lateral_cls, INIBasedModel)
                for key, value in lateral_dict.items():
                    assert lateral_cls.dict()[key] == value
예제 #9
0
 def test_given_coordinates_not_matching_numcoordinates_raises(
         self, x_coord: List[int], y_coord: List[int]):
     with pytest.raises(ValidationError):
         Lateral(
             id="42",
             discharge="bDischarge",
             numcoordinates=2,
             xcoordinates=x_coord,
             ycoordinates=y_coord,
         )
예제 #10
0
            def test_given_valid_location_args_constructs_lateral(
                    self, location_values: dict):
                # 1. Define test data.
                default_values = dict(
                    id="42",
                    discharge="eDischarge",
                    numcoordinates=2,
                    xcoordinates=[42, 24],
                    ycoordinates=[24, 42],
                    locationtype="1d",
                )
                test_dict = {**default_values, **location_values}

                # 2. Run test.
                new_lateral = Lateral(**test_dict)

                # 3. Validate final expectations.
                for key, value in location_values.items():
                    assert new_lateral.dict()[key] == value
예제 #11
0
 def test_given_numcoordinates_and_valid_coordinates(self):
     test_dict = dict(
         nodeid=None,
         branchid=None,
         chainage=None,
         numcoordinates=2,
         xcoordinates=[42, 24],
         ycoordinates=[24, 42],
     )
     return_value = Lateral.validate_location_dependencies(
         test_dict)
     assert return_value == test_dict
예제 #12
0
 def test_given_1d_args_and_1d_location_type(
         self, dict_values: dict):
     test_values = dict(
         numcoordinates=2,
         xcoordinates=[42, 24],
         ycoordinates=[24, 42],
         locationtype="1d",
     )
     test_dict = {**dict_values, **test_values}
     return_value = Lateral.validate_location_dependencies(
         test_dict)
     assert return_value == test_dict
예제 #13
0
 def test_given_unknown_locationtype_raises(self):
     with pytest.raises(ValidationError) as exc_mssg:
         location_type = "loremIpsum"
         Lateral(
             id="42",
             discharge="dDischarge",
             numcoordinates=2,
             xcoordinates=[42, 24],
             ycoordinates=[24, 42],
             locationtype=location_type,
         )
     expected_error_mssg = f"Value given ({location_type}) not accepted, should be one of: 1d, 2d, all"
     assert expected_error_mssg in str(exc_mssg.value)
예제 #14
0
            def test_given_coordinates_but_no_numcoordinates_raises(
                    self, x_coord: Optional[List[int]],
                    y_coord: Optional[List[int]]):
                with pytest.raises(ValidationError) as exc_mssg:
                    Lateral(
                        id="42",
                        discharge="aDischarge",
                        numcoordinates=None,
                        xcoordinates=x_coord,
                        ycoordinates=y_coord,
                    )

                expected_error_mssg = "numCoordinates should be given when providing xCoordinates or yCoordinates."
                assert expected_error_mssg in str(exc_mssg.value)
예제 #15
0
            def test_given_partial_coordinates_raises(self,
                                                      missing_coord: str):
                lateral_dict = dict(
                    id="42",
                    discharge="cDischarge",
                    numcoordinates=2,
                    xcoordinates=[42, 24],
                    ycoordinates=[24, 42],
                    locationtype="all",
                )
                lateral_dict[missing_coord.lower()] = None
                with pytest.raises(ValidationError) as exc_mssg:
                    Lateral(**lateral_dict)

                assert f"{missing_coord} should be given." in str(
                    exc_mssg.value)
예제 #16
0
 def test_given_correct_locationtype(self, location_type: str):
     return_value = Lateral.validate_location_type(location_type)
     assert return_value == location_type
예제 #17
0
 def test_given_correct_numcoordinates(self):
     return_value = Lateral.validate_coordinates(
         field_value=[42, 24], values=dict(numcoordinates=2))
     assert return_value == [42, 24]
예제 #18
0
 def test_given_1d_args_but_no_locationtype_then_sets_value(
         self, test_dict: dict, location_type: str):
     test_dict["locationtype"] = location_type
     return_value = Lateral.validate_location_dependencies(
         test_dict)
     assert return_value["locationtype"] == "1d"