This is an automated email from the ASF dual-hosted git repository.

jasonliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 92fee84c5c9 Enable PT011 rule to prvoider tests (#55980)
92fee84c5c9 is described below

commit 92fee84c5c9c07bfa14c02458ab9d3b5a49d9124
Author: Xch1 <[email protected]>
AuthorDate: Wed Sep 24 16:57:16 2025 +0800

    Enable PT011 rule to prvoider tests (#55980)
---
 .../oracle/tests/unit/oracle/hooks/test_oracle.py      |  9 ++++++---
 .../tests/unit/postgres/assets/test_postgres.py        |  9 +++++++--
 .../tests/unit/postgres/hooks/test_postgres.py         | 18 +++++-------------
 .../tests/unit/salesforce/hooks/test_salesforce.py     |  2 +-
 .../tests/unit/salesforce/operators/test_bulk.py       |  6 ++++--
 5 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/providers/oracle/tests/unit/oracle/hooks/test_oracle.py 
b/providers/oracle/tests/unit/oracle/hooks/test_oracle.py
index ade144d8d3e..11049b5f40f 100644
--- a/providers/oracle/tests/unit/oracle/hooks/test_oracle.py
+++ b/providers/oracle/tests/unit/oracle/hooks/test_oracle.py
@@ -419,7 +419,7 @@ class TestOracleHook:
 
     def test_bulk_insert_rows_no_rows(self):
         rows = []
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="parameter rows could not be None 
or empty iterable"):
             self.db_hook.bulk_insert_rows("table", rows)
 
     def test_bulk_insert_sequence_field(self):
@@ -436,18 +436,21 @@ class TestOracleHook:
         self.cur.executemany.assert_called_once_with(None, rows)
 
     def test_bulk_insert_sequence_without_parameter(self):
+        SEQUENCE_COLUMN_OR_NAME_PROVIDED = (
+            "Parameters 'sequence_column' and 'sequence_name' must be provided 
together or not at all."
+        )
         rows = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
         target_fields = ["col1", "col2", "col3"]
         sequence_column = "id"
         sequence_name = None
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
             self.db_hook.bulk_insert_rows(
                 "table", rows, target_fields, sequence_column=sequence_column, 
sequence_name=sequence_name
             )
 
         sequence_column = None
         sequence_name = "my_sequence"
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
             self.db_hook.bulk_insert_rows(
                 "table", rows, target_fields, sequence_column=sequence_column, 
sequence_name=sequence_name
             )
diff --git a/providers/postgres/tests/unit/postgres/assets/test_postgres.py 
b/providers/postgres/tests/unit/postgres/assets/test_postgres.py
index 82c64759a29..00e779b685b 100644
--- a/providers/postgres/tests/unit/postgres/assets/test_postgres.py
+++ b/providers/postgres/tests/unit/postgres/assets/test_postgres.py
@@ -56,11 +56,16 @@ def test_sanitize_uri_pass(original: str, normalized: str) 
-> None:
         pytest.param("postgres://", id="blank"),
         pytest.param("postgres:///database/schema/table", id="no-host"),
         pytest.param("postgres://example.com/database/table", 
id="missing-component"),
-        pytest.param("postgres://example.com:abcd/database/schema/table", 
id="non-port"),
         pytest.param("postgres://example.com/database/schema/table/column", 
id="extra-component"),
     ],
 )
 def test_sanitize_uri_fail(value: str) -> None:
     uri_i = urllib.parse.urlsplit(value)
-    with pytest.raises(ValueError):
+    with pytest.raises(ValueError, match="URI format postgres:// must 
contain"):
+        sanitize_uri(uri_i)
+
+
+def test_sanitize_uri_fail_non_port() -> None:
+    uri_i = 
urllib.parse.urlsplit("postgres://example.com:abcd/database/schema/table")
+    with pytest.raises(ValueError, match="Port could not be cast to integer 
value as 'abcd'"):
         sanitize_uri(uri_i)
diff --git a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py 
b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
index f394c561c2c..0607edc4405 100644
--- a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
+++ b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
@@ -209,7 +209,7 @@ class TestPostgresHookConn:
     @pytest.mark.usefixtures("mock_connect")
     def test_get_conn_with_invalid_cursor(self):
         self.connection.extra = '{"cursor": "mycursor"}'
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="Invalid cursor passed 
mycursor."):
             self.db_hook.get_conn()
 
     def test_get_conn_from_connection(self, mock_connect):
@@ -879,11 +879,9 @@ class TestPostgresHookPPG2:
             ),
         ]
         fields = ("id", "value")
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert 
syntax requires column names"):
             setup.db_hook.insert_rows(table, rows, replace=True, 
replace_index=fields[0])
 
-        assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax 
requires column names"
-
     def test_insert_rows_replace_missing_replace_index_arg(self, 
postgres_hook_setup):
         setup = postgres_hook_setup
         table = "table"
@@ -898,11 +896,9 @@ class TestPostgresHookPPG2:
             ),
         ]
         fields = ("id", "value")
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert 
syntax requires an unique index"):
             setup.db_hook.insert_rows(table, rows, fields, replace=True)
 
-        assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax 
requires an unique index"
-
     def test_insert_rows_replace_all_index(self, postgres_hook_setup):
         setup = postgres_hook_setup
         table = "table"
@@ -1145,11 +1141,9 @@ class TestPostgresHookPPG3:
             ),
         ]
         fields = ("id", "value")
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert 
syntax requires column names"):
             self.db_hook.insert_rows(table, rows, replace=True, 
replace_index=fields[0])
 
-        assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax 
requires column names"
-
     def test_insert_rows_replace_missing_replace_index_arg(self):
         table = "table"
         rows = [
@@ -1163,11 +1157,9 @@ class TestPostgresHookPPG3:
             ),
         ]
         fields = ("id", "value")
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert 
syntax requires an unique index"):
             self.db_hook.insert_rows(table, rows, fields, replace=True)
 
-        assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax 
requires an unique index"
-
     def test_insert_rows_replace_all_index(self):
         table = "table"
         rows = [
diff --git 
a/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py 
b/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py
index 9cb33157aee..39e2e41fde6 100644
--- a/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py
+++ b/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py
@@ -335,7 +335,7 @@ class TestSalesforceHook:
         assert salesforce_objects == mock_make_query.return_value
 
     def test_write_object_to_file_invalid_format(self):
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="Format value is not recognized: 
test"):
             self.salesforce_hook.write_object_to_file(query_results=[], 
filename="test", fmt="test")
 
     @patch(
diff --git a/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py 
b/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py
index 3ec701ecf41..f52e90a3238 100644
--- a/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py
+++ b/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py
@@ -40,7 +40,7 @@ class TestSalesforceBulkOperator:
                 payload=[],
             )
 
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="Operation 'operation' not 
found!"):
             SalesforceBulkOperator(
                 task_id="missing_operation",
                 operation="operation",
@@ -59,7 +59,9 @@ class TestSalesforceBulkOperator:
                 payload=[],
             )
 
-        with pytest.raises(ValueError):
+        with pytest.raises(
+            ValueError, match="The required parameter 'object_name' cannot 
have an empty value."
+        ):
             SalesforceBulkOperator(
                 task_id="missing_object_name",
                 operation="insert",

Reply via email to