def test_given_dict_values_doesnot_raise(self, dict_values: dict): required_values = dict(quantity="aQuantity", forcingfile=ForcingModel()) test_values = {**dict_values, **required_values} created_boundary = Boundary(**test_values) for key, value in test_values.items(): if key == "forcing_file": value = value.dict() assert created_boundary.dict()[key] == value
def test_given_no_values_raises_valueerror(self, dict_values: dict): with pytest.raises(ValueError) as exc_mssg: Boundary.check_nodeid_or_locationfile_present(dict_values) # 3. Verify final expectations. expected_error_mssg = ( "Either nodeId or locationFile fields should be specified." ) assert str(exc_mssg.value) == expected_error_mssg
def test_given_args_expected_values(self): # 1. Explicit declaration of parameters (to validate keys as they are written) dict_values = { "quantity": "42", "nodeid": "aNodeId", "locationfile": Path("aLocationFile"), "forcingfile": ForcingModel(), "bndwidth1d": 4.2, "bndbldepth": 2.4, } # 2. Create boundary. created_boundary = Boundary(**dict_values) # 3. Verify boundary values as expected. for key, value in dict_values.items(): assert created_boundary.dict()[key] == value
def test_boundary_with_forcing_file_without_match_returns_none(): forcing1 = _create_forcing("bnd1", "waterlevelbnd") forcing2 = _create_forcing("bnd2", "dischargebnd") forcing_file = ForcingModel(forcing=[forcing1, forcing2]) boundary = Boundary(nodeid="bnd3", quantity="qhbnd", forcingfile=forcing_file) assert boundary.forcing is None assert boundary.nodeid == "bnd3" assert boundary.quantity == "qhbnd"
def test_given_no_values_raises_valueerror(self, dict_values: dict): required_values = dict(quantity="aQuantity") test_values = {**dict_values, **required_values} with pytest.raises(ValueError) as exc_mssg: Boundary(**test_values) # 3. Verify final expectations. expected_error_mssg = ( "Either nodeId or locationFile fields should be specified." ) assert expected_error_mssg in str(exc_mssg.value)
def test_boundary_with_forcing_file_returns_forcing(): forcing1 = _create_forcing("bnd1", "waterlevelbnd") forcing2 = _create_forcing("bnd2", "dischargebnd") forcing3 = _create_forcing("bnd3", "qhbnd discharge") forcing_file = ForcingModel(forcing=[forcing1, forcing2, forcing3]) boundary2 = Boundary( nodeid="bnd2", quantity="dischargebnd", forcingfile=forcing_file ) assert boundary2.forcing is forcing2
def test_given_args_as_alias_expected_values(self): # 1. Explicit declaration of parameters (to validate keys as they are written) dict_values = { "quantity": "42", "nodeid": "aNodeId", "locationfile": Path("aLocationFile"), "forcingFile": ForcingModel(), "bndWidth1D": 4.2, "bndBlDepth": 2.4, } # 2. Create boundary. created_boundary = Boundary(**dict_values) boundary_as_dict = created_boundary.dict() # 3. Verify boundary values as expected. assert boundary_as_dict["quantity"] == dict_values["quantity"] assert boundary_as_dict["nodeid"] == dict_values["nodeid"] assert boundary_as_dict["locationfile"] == dict_values[ "locationfile"] assert boundary_as_dict["forcingfile"] == dict_values[ "forcingFile"] assert boundary_as_dict["bndwidth1d"] == dict_values["bndWidth1D"] assert boundary_as_dict["bndbldepth"] == dict_values["bndBlDepth"]
def test_given_dict_values_doesnot_raise(self, dict_values: dict): return_values = Boundary.check_nodeid_or_locationfile_present( dict_values) assert dict_values == return_values