Skip to content

Commit 92fee84

Browse files
authored
Enable PT011 rule to prvoider tests (#55980)
1 parent 68d4261 commit 92fee84

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

providers/oracle/tests/unit/oracle/hooks/test_oracle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def test_bulk_insert_rows_without_fields(self):
419419

420420
def test_bulk_insert_rows_no_rows(self):
421421
rows = []
422-
with pytest.raises(ValueError):
422+
with pytest.raises(ValueError, match="parameter rows could not be None or empty iterable"):
423423
self.db_hook.bulk_insert_rows("table", rows)
424424

425425
def test_bulk_insert_sequence_field(self):
@@ -436,18 +436,21 @@ def test_bulk_insert_sequence_field(self):
436436
self.cur.executemany.assert_called_once_with(None, rows)
437437

438438
def test_bulk_insert_sequence_without_parameter(self):
439+
SEQUENCE_COLUMN_OR_NAME_PROVIDED = (
440+
"Parameters 'sequence_column' and 'sequence_name' must be provided together or not at all."
441+
)
439442
rows = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
440443
target_fields = ["col1", "col2", "col3"]
441444
sequence_column = "id"
442445
sequence_name = None
443-
with pytest.raises(ValueError):
446+
with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
444447
self.db_hook.bulk_insert_rows(
445448
"table", rows, target_fields, sequence_column=sequence_column, sequence_name=sequence_name
446449
)
447450

448451
sequence_column = None
449452
sequence_name = "my_sequence"
450-
with pytest.raises(ValueError):
453+
with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
451454
self.db_hook.bulk_insert_rows(
452455
"table", rows, target_fields, sequence_column=sequence_column, sequence_name=sequence_name
453456
)

providers/postgres/tests/unit/postgres/assets/test_postgres.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ def test_sanitize_uri_pass(original: str, normalized: str) -> None:
5656
pytest.param("postgres://", id="blank"),
5757
pytest.param("postgres:///database/schema/table", id="no-host"),
5858
pytest.param("postgres://example.com/database/table", id="missing-component"),
59-
pytest.param("postgres://example.com:abcd/database/schema/table", id="non-port"),
6059
pytest.param("postgres://example.com/database/schema/table/column", id="extra-component"),
6160
],
6261
)
6362
def test_sanitize_uri_fail(value: str) -> None:
6463
uri_i = urllib.parse.urlsplit(value)
65-
with pytest.raises(ValueError):
64+
with pytest.raises(ValueError, match="URI format postgres:// must contain"):
65+
sanitize_uri(uri_i)
66+
67+
68+
def test_sanitize_uri_fail_non_port() -> None:
69+
uri_i = urllib.parse.urlsplit("postgres://example.com:abcd/database/schema/table")
70+
with pytest.raises(ValueError, match="Port could not be cast to integer value as 'abcd'"):
6671
sanitize_uri(uri_i)

providers/postgres/tests/unit/postgres/hooks/test_postgres.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_get_uri(self, mock_connect):
209209
@pytest.mark.usefixtures("mock_connect")
210210
def test_get_conn_with_invalid_cursor(self):
211211
self.connection.extra = '{"cursor": "mycursor"}'
212-
with pytest.raises(ValueError):
212+
with pytest.raises(ValueError, match="Invalid cursor passed mycursor."):
213213
self.db_hook.get_conn()
214214

215215
def test_get_conn_from_connection(self, mock_connect):
@@ -879,11 +879,9 @@ def test_insert_rows_replace_missing_target_field_arg(self, postgres_hook_setup)
879879
),
880880
]
881881
fields = ("id", "value")
882-
with pytest.raises(ValueError) as ctx:
882+
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires column names"):
883883
setup.db_hook.insert_rows(table, rows, replace=True, replace_index=fields[0])
884884

885-
assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires column names"
886-
887885
def test_insert_rows_replace_missing_replace_index_arg(self, postgres_hook_setup):
888886
setup = postgres_hook_setup
889887
table = "table"
@@ -898,11 +896,9 @@ def test_insert_rows_replace_missing_replace_index_arg(self, postgres_hook_setup
898896
),
899897
]
900898
fields = ("id", "value")
901-
with pytest.raises(ValueError) as ctx:
899+
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires an unique index"):
902900
setup.db_hook.insert_rows(table, rows, fields, replace=True)
903901

904-
assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires an unique index"
905-
906902
def test_insert_rows_replace_all_index(self, postgres_hook_setup):
907903
setup = postgres_hook_setup
908904
table = "table"
@@ -1145,11 +1141,9 @@ def test_insert_rows_replace_missing_target_field_arg(self):
11451141
),
11461142
]
11471143
fields = ("id", "value")
1148-
with pytest.raises(ValueError) as ctx:
1144+
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires column names"):
11491145
self.db_hook.insert_rows(table, rows, replace=True, replace_index=fields[0])
11501146

1151-
assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires column names"
1152-
11531147
def test_insert_rows_replace_missing_replace_index_arg(self):
11541148
table = "table"
11551149
rows = [
@@ -1163,11 +1157,9 @@ def test_insert_rows_replace_missing_replace_index_arg(self):
11631157
),
11641158
]
11651159
fields = ("id", "value")
1166-
with pytest.raises(ValueError) as ctx:
1160+
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires an unique index"):
11671161
self.db_hook.insert_rows(table, rows, fields, replace=True)
11681162

1169-
assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires an unique index"
1170-
11711163
def test_insert_rows_replace_all_index(self):
11721164
table = "table"
11731165
rows = [

providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def test_get_object_from_salesforce(self, mock_make_query):
335335
assert salesforce_objects == mock_make_query.return_value
336336

337337
def test_write_object_to_file_invalid_format(self):
338-
with pytest.raises(ValueError):
338+
with pytest.raises(ValueError, match="Format value is not recognized: test"):
339339
self.salesforce_hook.write_object_to_file(query_results=[], filename="test", fmt="test")
340340

341341
@patch(

providers/salesforce/tests/unit/salesforce/operators/test_bulk.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_execute_missing_operation(self):
4040
payload=[],
4141
)
4242

43-
with pytest.raises(ValueError):
43+
with pytest.raises(ValueError, match="Operation 'operation' not found!"):
4444
SalesforceBulkOperator(
4545
task_id="missing_operation",
4646
operation="operation",
@@ -59,7 +59,9 @@ def test_execute_missing_object_name(self):
5959
payload=[],
6060
)
6161

62-
with pytest.raises(ValueError):
62+
with pytest.raises(
63+
ValueError, match="The required parameter 'object_name' cannot have an empty value."
64+
):
6365
SalesforceBulkOperator(
6466
task_id="missing_object_name",
6567
operation="insert",

0 commit comments

Comments
 (0)