Skip to content

Commit

Permalink
Escape some regex metacharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Jan 6, 2025
1 parent 8ff34fa commit 8fca171
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/ert/ui_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@pytest.mark.filterwarnings("ignore::ert.config.ConfigWarning")
def test_bad_config_error_message(tmp_path):
(tmp_path / "test.ert").write_text("NUM_REL 10\n")
with pytest.raises(ConfigValidationError, match=r"NUM_REALIZATIONS must be set."):
with pytest.raises(ConfigValidationError, match="NUM_REALIZATIONS must be set\\."):
run_cli(TEST_RUN_MODE, "--disable-monitor", str(tmp_path / "test.ert"))


Expand Down
5 changes: 4 additions & 1 deletion tests/ert/unit_tests/config/test_analysis_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from textwrap import dedent

import hypothesis.strategies as st
Expand Down Expand Up @@ -104,7 +105,9 @@ def test_invalid_min_realization_raises_config_validation_error():
def test_invalid_design_matrix_format_raises_validation_error():
with pytest.raises(
ConfigValidationError,
match=r"DESIGN_MATRIX must be of format .xls or .xlsx; is 'my_matrix.txt'",
match=re.escape(
"DESIGN_MATRIX must be of format .xls or .xlsx; is 'my_matrix.txt'"
),
):
AnalysisConfig.from_dict(
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ert/unit_tests/config/test_gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_gen_kw_config():
def test_gen_kw_config_duplicate_keys_raises():
with pytest.raises(
ConfigValidationError,
match=r"Duplicate GEN_KW keys 'KEY2' found, keys must be unique.",
match=re.escape("Duplicate GEN_KW keys 'KEY2' found, keys must be unique."),
):
GenKwConfig(
name="KEY",
Expand Down
4 changes: 2 additions & 2 deletions tests/ert/unit_tests/config/test_surface_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_init_files_must_contain_placeholder_when_not_forward_init():
def test_when_base_surface_does_not_exist_gives_config_error():
with pytest.raises(
ConfigValidationError,
match=r"surface/small_out.irap not found",
match="surface/small_out\\.irap not found",
):
SurfaceConfig.from_config_list(
[
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_config_file_line_sets_the_corresponding_properties(
def test_invalid_surface_files_gives_config_error():
Path("base_surface.irap").write_text("not valid irap", encoding="utf-8")
with pytest.raises(
ConfigValidationError, match=r"Could not load surface 'base_surface.irap'"
ConfigValidationError, match="Could not load surface 'base_surface\\.irap'"
):
_ = SurfaceConfig.from_config_list(
[
Expand Down
2 changes: 1 addition & 1 deletion tests/ert/unit_tests/plugins/test_export_runpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_export_runpath_combination_parameter(writing_setup):

def test_export_runpath_bad_arguments(writing_setup):
writing_setup, config = writing_setup
with pytest.raises(ValueError, match=r"Expected |"):
with pytest.raises(ValueError, match="Expected \\|"):
writing_setup.export_job.run(config, ["wat"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_loading_of_eclipse_configurations(monkeypatch):
f.write("this:\n -should\n-be\ninvalid:yaml?")

monkeypatch.setenv("ECL100_SITE_CONFIG", "file.yml")
with pytest.raises(ValueError, match=r"Failed parse: file.yml as yaml"):
with pytest.raises(ValueError, match="Failed parse: file\\.yml as yaml"):
conf = ecl_config.Ecl100Config()

scalar_exe = "bin/scalar_exe"
Expand Down
6 changes: 3 additions & 3 deletions tests/ert/unit_tests/storage/test_local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_that_saving_empty_responses_fails_nicely(tmp_path):

with pytest.raises(
ValueError,
match=r"Responses RESPONSE are empty. Cannot proceed with saving to storage.",
match="Responses RESPONSE are empty\\. Cannot proceed with saving to storage\\.",
):
ensemble.save_response("RESPONSE", empty_data, 0)

Expand Down Expand Up @@ -193,7 +193,7 @@ def test_that_saving_empty_parameters_fails_nicely(tmp_path):
)
with pytest.raises(
ValueError,
match=r"Parameters PARAMETER are empty. Cannot proceed with saving to storage.",
match="Parameters PARAMETER are empty\\. Cannot proceed with saving to storage\\.",
):
prior.save_parameters("PARAMETER", 0, empty_data)

Expand Down Expand Up @@ -361,7 +361,7 @@ def test_open_storage_with_corrupted_storage(tmp_path):
with open_storage(tmp_path / "storage", mode="w") as storage:
storage.create_experiment().create_ensemble(name="prior", ensemble_size=1)
os.remove(tmp_path / "storage" / "index.json")
with pytest.raises(ErtStorageException, match=r"No index.json"):
with pytest.raises(ErtStorageException, match="No index\\.json"):
open_storage(tmp_path / "storage", mode="w")


Expand Down
4 changes: 2 additions & 2 deletions tests/ert/unit_tests/storage/test_parameter_sample_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ def test_gen_kw_forward_init(tmpdir, storage, load_forward_init):
with pytest.raises(
ConfigValidationError,
match=(
r"Loading GEN_KW from files created by "
r"the forward model is not supported."
"Loading GEN_KW from files created by "
"the forward model is not supported\\."
),
):
create_runpath(storage, "config.ert")
Expand Down
4 changes: 2 additions & 2 deletions tests/everest/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_variable_name_index_validation(copy_test_data_to_tmp):
config.input_constraints = input_constraints
with pytest.raises(
ValidationError,
match=r"does not match any instance of "
r"control_name.variable_name-variable_index",
match="does not match any instance of "
"control_name\\.variable_name-variable_index",
):
EverestConfig.model_validate(config.model_dump(exclude_none=True))

Expand Down

0 comments on commit 8fca171

Please sign in to comment.