11"""
22Unit tests for the PostgresCommentWriter.
33"""
4+
45import pytest
56from unittest .mock import MagicMock
67
@@ -85,7 +86,9 @@ def test_postgres_comment_writer_write_success(
8586def test_postgres_comment_writer_missing_db_connector ():
8687 """Tests that ConfigError is raised if db_connector is missing."""
8788 writer = PostgresCommentWriter ()
88- with pytest .raises (ConfigError , match = "PostgresCommentWriter requires 'db_connector'" ):
89+ with pytest .raises (
90+ ConfigError , match = "PostgresCommentWriter requires 'db_connector'"
91+ ):
8992 writer .write ({}, some_other_arg = "value" )
9093
9194
@@ -94,7 +97,10 @@ def test_postgres_comment_writer_wrong_db_connector_type():
9497 writer = PostgresCommentWriter ()
9598 mock_connector = MagicMock (spec = PostgresConnector )
9699 mock_connector .connection = None # Simulate not connected
97- with pytest .raises (ConfigError , match = "PostgresCommentWriter is only compatible with 'postgres'" ):
100+ with pytest .raises (
101+ ConfigError ,
102+ match = "PostgresCommentWriter is only compatible with 'postgres'" ,
103+ ):
98104 writer .write ({}, db_connector = MagicMock ()) # Pass a generic mock
99105
100106
@@ -110,11 +116,15 @@ def test_postgres_comment_writer_db_error_rollback(
110116 mock_postgres_connector , mock_catalog_data
111117):
112118 """Tests that changes are rolled back on database error."""
113- mock_postgres_connector .cursor .execute .side_effect = Exception ("DB write error" )
119+ mock_postgres_connector .cursor .execute .side_effect = Exception (
120+ "DB write error"
121+ )
114122
115123 writer = PostgresCommentWriter ()
116- with pytest .raises (WriterError , match = "Error writing comments to PostgreSQL" ):
124+ with pytest .raises (
125+ WriterError , match = "Error writing comments to PostgreSQL"
126+ ):
117127 writer .write (mock_catalog_data , db_connector = mock_postgres_connector )
118128
119129 mock_postgres_connector .connection .commit .assert_not_called ()
120- mock_postgres_connector .connection .rollback .assert_called_once ()
130+ mock_postgres_connector .connection .rollback .assert_called_once ()
0 commit comments