chore: enforce more ruff rules (#31447)

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
Maxime Beauchemin
2024-12-18 17:41:34 -08:00
committed by GitHub
parent 9da65d6bfd
commit e51b95ffa8
375 changed files with 1821 additions and 1718 deletions

View File

@@ -305,7 +305,7 @@ class TestDbEngineSpecs(TestDbEngineSpec):
}
sql = table.get_query_str(query_obj)
assert (
"ORDER BY \n case\n when gender='boy' then 'male'\n else 'female'\n end\n ASC"
"ORDER BY \n case\n when gender='boy' then 'male'\n else 'female'\n end\n ASC" # noqa: E501
in sql
)

View File

@@ -248,11 +248,11 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
)
def test_extract_errors(self):
msg = "403 POST https://bigquery.googleapis.com/bigquery/v2/projects/test-keel-310804/jobs?prettyPrint=false: Access Denied: Project profound-keel-310804: User does not have bigquery.jobs.create permission in project profound-keel-310804"
msg = "403 POST https://bigquery.googleapis.com/bigquery/v2/projects/test-keel-310804/jobs?prettyPrint=false: Access Denied: Project profound-keel-310804: User does not have bigquery.jobs.create permission in project profound-keel-310804" # noqa: E501
result = BigQueryEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='Unable to connect. Verify that the following roles are set on the service account: "BigQuery Data Viewer", "BigQuery Metadata Viewer", "BigQuery Job User" and the following permissions are set "bigquery.readsessions.create", "bigquery.readsessions.getData"',
message='Unable to connect. Verify that the following roles are set on the service account: "BigQuery Data Viewer", "BigQuery Metadata Viewer", "BigQuery Job User" and the following permissions are set "bigquery.readsessions.create", "bigquery.readsessions.getData"', # noqa: E501
error_type=SupersetErrorType.CONNECTION_DATABASE_PERMISSIONS_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -267,11 +267,11 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
)
]
msg = "bigquery error: 404 Not found: Dataset fakeDataset:bogusSchema was not found in location"
msg = "bigquery error: 404 Not found: Dataset fakeDataset:bogusSchema was not found in location" # noqa: E501
result = BigQueryEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='The schema "bogusSchema" does not exist. A valid schema must be used to run this query.',
message='The schema "bogusSchema" does not exist. A valid schema must be used to run this query.', # noqa: E501
error_type=SupersetErrorType.SCHEMA_DOES_NOT_EXIST_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -279,22 +279,22 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1004,
"message": "Issue 1004 - The column was deleted or renamed in the database.",
"message": "Issue 1004 - The column was deleted or renamed in the database.", # noqa: E501
},
],
},
)
]
msg = 'Table name "badtable" missing dataset while no default dataset is set in the request'
msg = 'Table name "badtable" missing dataset while no default dataset is set in the request' # noqa: E501
result = BigQueryEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='The table "badtable" does not exist. A valid table must be used to run this query.',
message='The table "badtable" does not exist. A valid table must be used to run this query.', # noqa: E501
error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -302,11 +302,11 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1005,
"message": "Issue 1005 - The table was deleted or renamed in the database.",
"message": "Issue 1005 - The table was deleted or renamed in the database.", # noqa: E501
},
],
},
@@ -325,11 +325,11 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1004,
"message": "Issue 1004 - The column was deleted or renamed in the database.",
"message": "Issue 1004 - The column was deleted or renamed in the database.", # noqa: E501
},
],
},
@@ -340,7 +340,7 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
result = BigQueryEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='Please check your query for syntax errors at or near "from_". Then, try running your query again.',
message='Please check your query for syntax errors at or near "from_". Then, try running your query again.', # noqa: E501
error_type=SupersetErrorType.SYNTAX_ERROR,
level=ErrorLevel.ERROR,
extra={

View File

@@ -28,7 +28,7 @@ class TestGsheetsDbEngineSpec(TestDbEngineSpec):
result = GSheetsEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='Please check your query for syntax errors near "from_". Then, try running your query again.',
message='Please check your query for syntax errors near "from_". Then, try running your query again.', # noqa: E501
error_type=SupersetErrorType.SYNTAX_ERROR,
level=ErrorLevel.ERROR,
extra={

View File

@@ -33,7 +33,7 @@ def test_0_progress():
log = """
17/02/07 18:26:27 INFO log.PerfLogger: <PERFLOG method=compile from=org.apache.hadoop.hive.ql.Driver>
17/02/07 18:26:27 INFO log.PerfLogger: <PERFLOG method=parse from=org.apache.hadoop.hive.ql.Driver>
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 0
@@ -57,7 +57,7 @@ def test_job_1_launched_stage_1():
17/02/07 19:15:55 INFO ql.Driver: Total jobs = 2
17/02/07 19:15:55 INFO ql.Driver: Launching Job 1 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 0
@@ -67,7 +67,7 @@ def test_job_1_launched_stage_1_map_40_progress(): # pylint: disable=invalid-na
17/02/07 19:15:55 INFO ql.Driver: Launching Job 1 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 10
@@ -78,7 +78,7 @@ def test_job_1_launched_stage_1_map_80_reduce_40_progress(): # pylint: disable=
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 80%, reduce = 40%
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 30
@@ -91,7 +91,7 @@ def test_job_1_launched_stage_2_stages_progress(): # pylint: disable=invalid-na
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 80%, reduce = 40%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-2 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 100%, reduce = 0%
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 12
@@ -103,7 +103,7 @@ def test_job_2_launched_stage_2_stages_progress(): # pylint: disable=invalid-na
17/02/07 19:15:55 INFO ql.Driver: Launching Job 2 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
""".split("\n")
""".split("\n") # noqa: E501
assert HiveEngineSpec.progress(log) == 60

View File

@@ -170,18 +170,18 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1015,
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.", # noqa: E501
}
],
},
)
]
msg = "check the manual that corresponds to your MySQL server version for the right syntax to use near 'from_"
msg = "check the manual that corresponds to your MySQL server version for the right syntax to use near 'from_" # noqa: E501
result = MySQLEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='Please check your query for syntax errors near "from_". Then, try running your query again.',
message='Please check your query for syntax errors near "from_". Then, try running your query again.', # noqa: E501
error_type=SupersetErrorType.SYNTAX_ERROR,
level=ErrorLevel.ERROR,
extra={

View File

@@ -81,10 +81,10 @@ class TestPinotDbEngineSpec(TestDbEngineSpec):
assert result == expected
def test_invalid_get_time_expression_arguments(self):
with self.assertRaises(NotImplementedError):
with self.assertRaises(NotImplementedError): # noqa: PT027
PinotEngineSpec.get_timestamp_expr(column("tstamp"), None, "P0.25Y")
with self.assertRaises(NotImplementedError):
with self.assertRaises(NotImplementedError): # noqa: PT027
PinotEngineSpec.get_timestamp_expr(
column("tstamp"), "epoch_s", "invalid_grain"
)

View File

@@ -176,7 +176,7 @@ class TestPostgresDbEngineSpec(TestDbEngineSpec):
"""
)
sql = "DROP TABLE birth_names"
with self.assertRaises(errors.SyntaxError):
with self.assertRaises(errors.SyntaxError): # noqa: PT027
PostgresEngineSpec.estimate_statement_cost(database, sql, cursor)
def test_query_cost_formatter_example_costs(self):
@@ -396,11 +396,11 @@ psql: error: could not connect to server: Operation timed out
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong.",
"message": "Issue 1014 - Either the username or the password is wrong.", # noqa: E501
},
{
"code": 1015,
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.", # noqa: E501
},
],
},
@@ -411,7 +411,7 @@ psql: error: could not connect to server: Operation timed out
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='Please check your query for syntax errors at or near "from_". Then, try running your query again.',
message='Please check your query for syntax errors at or near "from_". Then, try running your query again.', # noqa: E501
error_type=SupersetErrorType.SYNTAX_ERROR,
level=ErrorLevel.ERROR,
extra={

View File

@@ -922,7 +922,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
mock_database = mock.MagicMock()
mock_cursor = mock.MagicMock()
mock_cursor.execute.side_effect = Exception()
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017, PT027
PrestoEngineSpec.estimate_statement_cost(
mock_database, "DROP TABLE brth_names", mock_cursor
)
@@ -946,7 +946,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
database.get_raw_connection().__enter__().cursor().execute = mock_execute
schema = "schema"
table = "table"
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017, PT027
PrestoEngineSpec.get_create_view(database, schema=schema, table=table)
def test_get_create_view_database_error(self):
@@ -997,7 +997,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1002,
"message": "Issue 1002 - The database returned an unexpected error.",
"message": "Issue 1002 - The database returned an unexpected error.", # noqa: E501
}
],
},
@@ -1016,11 +1016,11 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1004,
"message": "Issue 1004 - The column was deleted or renamed in the database.",
"message": "Issue 1004 - The column was deleted or renamed in the database.", # noqa: E501
},
],
},
@@ -1031,7 +1031,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
result = PrestoEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message="The table \"'tpch.tiny.region2'\" does not exist. A valid table must be used to run this query.",
message="The table \"'tpch.tiny.region2'\" does not exist. A valid table must be used to run this query.", # noqa: E501
error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -1039,11 +1039,11 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1005,
"message": "Issue 1005 - The table was deleted or renamed in the database.",
"message": "Issue 1005 - The table was deleted or renamed in the database.", # noqa: E501
},
],
},
@@ -1054,7 +1054,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
result = PrestoEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
message='The schema "tin" does not exist. A valid schema must be used to run this query.',
message='The schema "tin" does not exist. A valid schema must be used to run this query.', # noqa: E501
error_type=SupersetErrorType.SCHEMA_DOES_NOT_EXIST_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -1062,11 +1062,11 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1003,
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.", # noqa: E501
},
{
"code": 1016,
"message": "Issue 1005 - The schema was deleted or renamed in the database.",
"message": "Issue 1005 - The schema was deleted or renamed in the database.", # noqa: E501
},
],
},
@@ -1085,14 +1085,14 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong.",
"message": "Issue 1014 - Either the username or the password is wrong.", # noqa: E501
}
],
},
)
]
msg = "Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known"
msg = "Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known" # noqa: E501
result = PrestoEngineSpec.extract_errors(
Exception(msg), {"hostname": "badhost"}
)
@@ -1106,7 +1106,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided can't be resolved.", # noqa: E501
}
],
},
@@ -1119,7 +1119,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
)
assert result == [
SupersetError(
message='The host "badhost" might be down, and can\'t be reached on port 12345.',
message='The host "badhost" might be down, and can\'t be reached on port 12345.', # noqa: E501
error_type=SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
level=ErrorLevel.ERROR,
extra={
@@ -1127,7 +1127,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", # noqa: E501
}
],
},
@@ -1164,7 +1164,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
"issue_codes": [
{
"code": 1015,
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.", # noqa: E501
}
],
},