def test_create_json_from_csv_without_providing_parameters_raises_MissingParameterError( ): with pytest.raises(A1.MissingParameterError): A1.create_json_from_csv(DUMMY_CSV_PATH, "csv_comma", parameters=[], asset_is_a_storage=False)
def test_create_json_from_csv_storage_raises_WrongStorageColumn(): with pytest.raises(A1.WrongStorageColumn): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_column_name", parameters=[AGE_INSTALLED, DEVELOPMENT_COSTS], asset_is_a_storage=True, )
def test_create_json_from_csv_storage_raises_WrongParameterWarning(): with pytest.warns(A1.WrongParameterWarning): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_parameter", parameters=[AGE_INSTALLED, DEVELOPMENT_COSTS], asset_is_a_storage=True, )
def test_create_json_from_csv_with_unknown_separator_for_csv_raises_CsvParsingError(): with pytest.raises(CsvParsingError): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_unknown_separator", CSV_PARAMETERS, asset_is_a_storage=False, )
def test_create_json_from_csv_with_uncomplete_parameters_raises_WrongParameterWarning( ): with pytest.raises(A1.MissingParameterError): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_comma", parameters=["param1", "param2", "param3"], asset_is_a_storage=False, )
def test_create_json_from_csv_with_wrong_parameters_raises_WrongParameterWarning( ): with pytest.warns(A1.WrongParameterWarning): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_wrong_parameter", parameters=["param1", "param2"], asset_is_a_storage=False, )
def test_create_json_from_csv_with_wrong_parameters_raises_loggin_warning(caplog): with caplog.at_level(logging.WARNING): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_wrong_parameter", parameters=["param1", "param2"], asset_is_a_storage=False, ) assert ( ".csv is not expected." in caplog.text ), f"There is an unexpected/wrong parameter in the inputs, but it is not recognized as such."
def test_create_json_from_csv_storage_raises_logging_warning(caplog): with caplog.at_level(logging.WARNING): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_parameter", parameters=[AGE_INSTALLED, DEVELOPMENT_COSTS], asset_is_a_storage=True, ) assert ( "is not recognized." in caplog.text ), f"There is a unexpected/wrong parameter provided in the storage asset, but it is not recognized as such."
def test_create_json_from_csv_storage_raises_logging_warning_for_wrong_values(caplog): with caplog.at_level(logging.WARNING): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_values", parameters=[AGE_INSTALLED, DEVELOPMENT_COSTS], asset_is_a_storage=True, ) assert ( "be set to NaN." in caplog.text ), f"There is parameter with a wrong value in provided in the storage asset, but it is not recognized as suchblack ."
def test_create_json_from_csv_float_int_parsing(): exp = { "param1": { UNIT: "years", VALUE: 50.0 }, "param2": { UNIT: "factor", VALUE: 0.2 }, "param3": { UNIT: "currency", VALUE: 65.5 }, } json = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_float_int", parameters=["param1", "param2", "param3"], asset_is_a_storage=False, ) for param in exp: assert json["csv_float_int"]["col1"][param][VALUE] == exp[param][VALUE] assert type(json["csv_float_int"]["col1"]["param1"][VALUE]) is int assert type(json["csv_float_int"]["col1"]["param2"][VALUE]) is float assert type(json["csv_float_int"]["col1"]["param3"][VALUE]) is float
def test_create_json_from_csv_without_providing_parameters_raises_MissingParameterError(): with pytest.raises(MissingParameterError): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_comma", parameters=[], asset_is_a_storage=False ) utils.compare_input_parameters_with_reference(d, flag_missing=True)
def test_create_json_from_csv_with_ampersand_separated_csv(): d = A1.create_json_from_csv(DUMMY_CSV_PATH, "csv_ampersand", CSV_PARAMETERS, asset_is_a_storage=False) assert d == {"csv_ampersand": CSV_EXAMPLE}
def test_default_values_storage_with_thermal_losses(): exp = { THERM_LOSSES_REL: {UNIT: "no_unit", VALUE: 0.001}, THERM_LOSSES_ABS: {UNIT: "kWh", VALUE: 0.00001}, } data_path = os.path.join( TEST_REPO_PATH, "benchmark_test_inputs", "Feature_stratified_thermal_storage", "csv_elements", ) json = A1.create_json_from_csv( input_directory=data_path, filename="storage_fix_with_fixed_thermal_losses_float", parameters=[ "age_installed", "development_costs", "specific_costs", "efficiency", "installedCap", "lifetime", "specific_costs_om", "unit", ], asset_is_a_storage=True, ) for param, result in exp.items(): assert ( json["storage capacity"][param][VALUE] == result[VALUE] ), f"{param} should match {result[VALUE]}"
def test_create_json_from_csv_storage_raises_MissingParameterError(): with pytest.raises(A1.MissingParameterError): A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_parameter", parameters=[ AGE_INSTALLED, DEVELOPMENT_COSTS, C_RATE, DISPATCH_PRICE, SOC_INITIAL, SOC_MAX, SOC_MIN, INSTALLED_CAP, ], asset_is_a_storage=True, )
def test_create_json_from_csv_ignore_extra_parameters_in_csv(): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_wrong_parameter", parameters=["param1", "param2"], asset_is_a_storage=False, ) assert d == {"csv_wrong_parameter": CSV_EXAMPLE}
def test_create_json_from_csv_for_list(): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_list", parameters=["param1", "param2", "param3", "param4", "param5"], asset_is_a_storage=False, ) for k, v in d["csv_list"]["col1"].items(): assert v == CSV_LIST[k]
def test_create_json_from_csv_for_time_series(): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_timeseries", parameters=["param1"], asset_is_a_storage=False, ) for k, v in d["csv_timeseries"]["col1"].items(): assert v == CSV_TIMESERIES[k]
def test_create_json_from_csv_storage_raises_MissingParameterError(): with pytest.raises(MissingParameterError): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_storage_wrong_parameter", parameters=[ AGE_INSTALLED, DEVELOPMENT_COSTS, C_RATE, DISPATCH_PRICE, SOC_INITIAL, SOC_MAX, SOC_MIN, INSTALLED_CAP, ], asset_is_a_storage=True, ) utils.compare_input_parameters_with_reference(d, flag_missing=True)
def test_conversion(): d = A1.create_json_from_csv( DUMMY_CSV_PATH, "csv_type", parameters=[ "param_str", "param_factor", "param_cur", "param_bool1", "param_bool2", "param_bool3", "param_bool4", "param_bool5", "param_bool6", "param_year", ], asset_is_a_storage=False, ) for k, v in d["csv_type"]["col1"].items(): assert v == CONVERSION_TYPE[k]
def test_create_json_from_csv_file_not_exist_raises_filenotfound_error(): with pytest.raises(FileNotFoundError): A1.create_json_from_csv(input_directory=CSV_PATH, filename="not_existing", parameters=[])