diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5ac5137..c62751b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: id: ruff - id: ruff-format repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.8.0 - hooks: - entry: script/build_xquery_type_dicts id: build-xquery-type-dicts diff --git a/tests/client/test_advanced_search.py b/tests/client/test_advanced_search.py index 5d38f7a8..84a3f04f 100644 --- a/tests/client/test_advanced_search.py +++ b/tests/client/test_advanced_search.py @@ -128,10 +128,13 @@ def test_user_can_view_unpublished_but_show_unpublished_is_false( When the advanced_search method is called with the show_unpublished parameter set to False Then it should call the MarkLogic module with the expected query parameters """ - with patch.object(self.client, "invoke") as mock_invoke, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=True, + with ( + patch.object(self.client, "invoke") as mock_invoke, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=True, + ), ): self.client.advanced_search( SearchParameters( @@ -177,10 +180,13 @@ def test_user_can_view_unpublished_and_show_unpublished_is_true( When the advanced_search method is called with the show_unpublished parameter set to True Then it should call the MarkLogic module with the expected query parameters """ - with patch.object(self.client, "invoke") as patched_invoke, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=True, + with ( + patch.object(self.client, "invoke") as patched_invoke, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=True, + ), ): self.client.advanced_search( SearchParameters( @@ -204,11 +210,15 @@ def test_user_cannot_view_unpublished_but_show_unpublished_is_true( When the advanced_search method is called with the show_unpublished parameter set to True Then it should call the MarkLogic module with the show_unpublished parameter set to False and log a warning """ - with patch.object(self.client, "invoke") as patched_invoke, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=False, - ), patch.object(logging, "warning") as mock_logging: + with ( + patch.object(self.client, "invoke") as patched_invoke, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=False, + ), + patch.object(logging, "warning") as mock_logging, + ): self.client.advanced_search( SearchParameters( query="my-query", diff --git a/tests/client/test_checkout_checkin_judgment.py b/tests/client/test_checkout_checkin_judgment.py index f6377c65..7568fd44 100644 --- a/tests/client/test_checkout_checkin_judgment.py +++ b/tests/client/test_checkout_checkin_judgment.py @@ -30,10 +30,13 @@ def test_checkout_judgment(self): ) def test_checkout_judgment_with_midnight_timeout(self): - with patch.object(self.client, "eval") as mock_eval, patch.object( - self.client, - "calculate_seconds_until_midnight", - return_value=3600, + with ( + patch.object(self.client, "eval") as mock_eval, + patch.object( + self.client, + "calculate_seconds_until_midnight", + return_value=3600, + ), ): uri = DocumentURIString("ewca/civ/2004/632") annotation = "locked by A KITTEN" diff --git a/tests/client/test_eval_xslt.py b/tests/client/test_eval_xslt.py index 2c40ac73..334dce0c 100644 --- a/tests/client/test_eval_xslt.py +++ b/tests/client/test_eval_xslt.py @@ -15,10 +15,13 @@ def setUp(self): @patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True) def test_eval_xslt_user_can_view_unpublished(self): - with patch.object(self.client, "eval") as mock_eval, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=True, + with ( + patch.object(self.client, "eval") as mock_eval, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=True, + ), ): uri = DocumentURIString("judgment/uri") expected_vars: XsltTransformDict = { @@ -38,11 +41,15 @@ def test_eval_xslt_user_can_view_unpublished(self): def test_eval_xslt_user_cannot_view_unpublished(self): """The user is not permitted to see unpublished judgments but is attempting to view them Set `show_unpublished` to false and log a warning""" - with patch.object(self.client, "eval") as mock_eval, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=False, - ), patch.object(logging, "warning") as mock_logging: + with ( + patch.object(self.client, "eval") as mock_eval, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=False, + ), + patch.object(logging, "warning") as mock_logging, + ): uri = DocumentURIString("judgment/uri") expected_vars: XsltTransformDict = { "uri": MarkLogicDocumentURIString("/judgment/uri.xml"), @@ -62,10 +69,13 @@ def test_eval_xslt_user_cannot_view_unpublished(self): @patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True) def test_eval_xslt_with_filename(self): - with patch.object(self.client, "eval") as mock_eval, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=True, + with ( + patch.object(self.client, "eval") as mock_eval, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=True, + ), ): uri = DocumentURIString("judgment/uri") expected_vars: XsltTransformDict = { @@ -87,10 +97,13 @@ def test_eval_xslt_with_filename(self): @patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True) def test_eval_xslt_with_query(self): - with patch.object(self.client, "eval") as mock_eval, patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=True, + with ( + patch.object(self.client, "eval") as mock_eval, + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=True, + ), ): uri = DocumentURIString("judgment/uri") query = "the query string" diff --git a/tests/client/test_get_set_metadata.py b/tests/client/test_get_set_metadata.py index eab07607..321b646e 100644 --- a/tests/client/test_get_set_metadata.py +++ b/tests/client/test_get_set_metadata.py @@ -132,10 +132,13 @@ def test_set_document_date(self): assert mock_eval.call_args.kwargs["vars"] == json.dumps(expected_vars) def test_set_judgment_date_warn(self): - with patch.object(warnings, "warn") as mock_warn, patch.object( - self.client, - "eval", - ) as mock_eval: + with ( + patch.object(warnings, "warn") as mock_warn, + patch.object( + self.client, + "eval", + ) as mock_eval, + ): uri = DocumentURIString("judgment/uri") content = "2022-01-01" expected_vars = {"uri": "/judgment/uri.xml", "content": "2022-01-01"} diff --git a/tests/client/test_save_copy_delete_judgment.py b/tests/client/test_save_copy_delete_judgment.py index a9f728f1..bab7c90d 100644 --- a/tests/client/test_save_copy_delete_judgment.py +++ b/tests/client/test_save_copy_delete_judgment.py @@ -62,9 +62,10 @@ def test_save_locked_judgment_xml(self): When `Client.save_locked_judgment_xml` is called with these as arguments Then the xquery in `update_locked_judgment.xqy` is called on the Marklogic db with those arguments """ - with patch.object(caselawclient.Client, "validate_content_hash"), patch.object( - self.client, "eval" - ) as mock_eval: + with ( + patch.object(caselawclient.Client, "validate_content_hash"), + patch.object(self.client, "eval") as mock_eval, + ): uri = DocumentURIString("ewca/civ/2004/632") judgment_str = "My updated judgment" judgment_xml = judgment_str.encode("utf-8") diff --git a/tests/client/test_verify_show_unpublished.py b/tests/client/test_verify_show_unpublished.py index 50eb7fc3..0cc7e292 100644 --- a/tests/client/test_verify_show_unpublished.py +++ b/tests/client/test_verify_show_unpublished.py @@ -13,11 +13,14 @@ def setUp(self): # and with them asking for unpublished judgments or not def test_hide_published_if_unauthorised_and_user_asks_for_unpublished(self): # User cannot view unpublished but is asking to view unpublished judgments - with patch.object( - self.client, - "user_can_view_unpublished_judgments", - return_value=False, - ), patch.object(logging, "warning") as mock_logger: + with ( + patch.object( + self.client, + "user_can_view_unpublished_judgments", + return_value=False, + ), + patch.object(logging, "warning") as mock_logger, + ): result = self.client.verify_show_unpublished(True) assert result is False # Check the logger was called diff --git a/tests/models/documents/test_documents.py b/tests/models/documents/test_documents.py index dd065a6f..b3b7bdfa 100644 --- a/tests/models/documents/test_documents.py +++ b/tests/models/documents/test_documents.py @@ -283,15 +283,18 @@ def test_returns_true_when_enriched_recently_is_true_and_validates_against_schem can_enrich, ): document = Document(DocumentURIString("test/1234"), mock_api_client) - with patch.object( - Document, - "enriched_recently", - new_callable=PropertyMock, - ) as mock_enriched_recently, patch.object( - Document, - "validates_against_schema", - new_callable=PropertyMock, - ) as mock_validates_against_schema: + with ( + patch.object( + Document, + "enriched_recently", + new_callable=PropertyMock, + ) as mock_enriched_recently, + patch.object( + Document, + "validates_against_schema", + new_callable=PropertyMock, + ) as mock_validates_against_schema, + ): mock_enriched_recently.return_value = enriched_recently mock_validates_against_schema.return_value = validates_against_schema