Skip to content

Commit

Permalink
chore(test): use regex.escape everywhere (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Mar 21, 2024
1 parent c73b126 commit d0061db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions test/integration/commands/project/test_create_project.py
Expand Up @@ -2,6 +2,7 @@
from typing import Any

import pytest
import regex

from dsp_tools.commands.project.create.project_create import _sort_prop_classes
from dsp_tools.commands.project.create.project_create import _sort_resources
Expand Down Expand Up @@ -63,13 +64,13 @@ def test_sort_prop_classes(tp_systematic_ontology: dict[str, Any]) -> None:
def test_validate_project(tp_systematic: dict[str, Any], tp_circular_ontology: dict[str, Any]) -> None:
assert validate_project(tp_systematic) is True

with pytest.raises(BaseError, match=r"Input 'fantasy.xyz' is neither a file path nor a JSON object."):
with pytest.raises(BaseError, match=regex.escape("Input 'fantasy.xyz' is neither a file path nor a JSON object.")):
validate_project("fantasy.xyz")

with pytest.raises(BaseError, match=r"validation error: 'hasColor' does not match"):
with pytest.raises(BaseError, match=regex.escape("validation error: 'hasColor' does not match")):
validate_project("testdata/invalid-testdata/json-project/invalid-super-property.json")

with pytest.raises(BaseError, match=r"ERROR: Your ontology contains properties derived from 'hasLinkTo'"):
with pytest.raises(BaseError, match=regex.escape("Your ontology contains properties derived from 'hasLinkTo'")):
validate_project(tp_circular_ontology)


Expand Down
Expand Up @@ -68,7 +68,9 @@ def test_error_on_nonexistent_shortcode() -> None:
shortcode="9999",
default_ontology="foo",
)
with pytest.raises(UserError, match="A project with shortcode 9999 could not be found on the DSP server"):
with pytest.raises(
UserError, match=regex.escape("A project with shortcode 9999 could not be found on the DSP server")
):
do_xml_consistency_check_with_ontology(ontology_client, root)


Expand Down
4 changes: 2 additions & 2 deletions test/unittests/commands/test_id2iri.py
Expand Up @@ -21,15 +21,15 @@ def mapping() -> dict[str, str]:


def test_invalid_xml_file_name() -> None:
with pytest.raises(BaseError, match=r"File test\.xml could not be found"):
with pytest.raises(BaseError, match=regex.escape("File test.xml could not be found")):
id2iri(
xml_file="test.xml",
json_file="testdata/id2iri/test-id2iri-mapping.json",
)


def test_invalid_json_file_name() -> None:
with pytest.raises(BaseError, match=r"File test\.json could not be found"):
with pytest.raises(BaseError, match=regex.escape("File test.json could not be found")):
id2iri(
xml_file="testdata/id2iri/test-id2iri-data.xml",
json_file="test.json",
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/utils/test_connection_live.py
Expand Up @@ -59,7 +59,7 @@ def test_log_in_bad_credentials() -> None:
con._log_response = Mock()
con.session.request = Mock(return_value=Mock(status_code=401))
with patch("dsp_tools.utils.connection_live.time.sleep") as sleep_mock:
with pytest.raises(UserError, match="Username and/or password are not valid"):
with pytest.raises(UserError, match=regex.escape("Username and/or password are not valid")):
con.login("invalid@example.com", "wrong")
sleep_mock.assert_not_called()

Expand Down

0 comments on commit d0061db

Please sign in to comment.