chore: set up ruff as a new linter/formatter (#28158)

This commit is contained in:
Maxime Beauchemin
2024-04-24 17:19:53 -07:00
committed by GitHub
parent e8a678b75a
commit 2d63722150
579 changed files with 2508 additions and 2542 deletions

View File

@@ -16,6 +16,7 @@
# under the License.
# isort:skip_file
"""Unit tests for Superset"""
import json
import unittest
import copy
@@ -32,20 +33,20 @@ from tests.integration_tests.conftest import with_feature_flags
from superset.charts.data.api import ChartDataRestApi
from superset.models.sql_lab import Query
from tests.integration_tests.base_tests import SupersetTestCase, test_client
from tests.integration_tests.annotation_layers.fixtures import create_annotation_layers
from tests.integration_tests.annotation_layers.fixtures import create_annotation_layers # noqa: F401
from tests.integration_tests.constants import (
ADMIN_USERNAME,
GAMMA_NO_CSV_USERNAME,
GAMMA_USERNAME,
)
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
load_birth_names_data,
load_birth_names_dashboard_with_slices, # noqa: F401
load_birth_names_data, # noqa: F401
)
from tests.integration_tests.test_app import app
from tests.integration_tests.fixtures.energy_dashboard import (
load_energy_table_with_slice,
load_energy_table_data,
load_energy_table_with_slice, # noqa: F401
load_energy_table_data, # noqa: F401
)
import pytest
from superset.models.slice import Slice
@@ -69,7 +70,7 @@ from superset.common.chart_data import ChartDataResultFormat, ChartDataResultTyp
from tests.common.query_context_generator import ANNOTATION_LAYERS
from tests.integration_tests.fixtures.query_context import get_query_context
from tests.integration_tests.test_app import app
from tests.integration_tests.test_app import app # noqa: F811
CHART_DATA_URI = "api/v1/chart/data"
@@ -131,7 +132,9 @@ class BaseTestChartDataApi(SupersetTestCase):
def quote_name(self, name: str):
if get_main_database().backend in {"presto", "hive"}:
with get_example_database().get_inspector_with_context() as inspector: # E: Ne
with (
get_example_database().get_inspector_with_context() as inspector
): # E: Ne
return inspector.engine.dialect.identifier_preparer.quote_identifier(
name
)
@@ -636,9 +639,9 @@ class TestPostChartDataApi(BaseTestChartDataApi):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_with_invalid_where_parameter_closing_unclosed__400(self):
self.query_context_payload["queries"][0]["filters"] = []
self.query_context_payload["queries"][0]["extras"][
"where"
] = "state = 'CA') OR (state = 'NY'"
self.query_context_payload["queries"][0]["extras"]["where"] = (
"state = 'CA') OR (state = 'NY'"
)
rv = self.post_assert_metric(CHART_DATA_URI, self.query_context_payload, "data")
@@ -672,9 +675,9 @@ class TestPostChartDataApi(BaseTestChartDataApi):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_with_invalid_having_parameter_closing_and_comment__400(self):
self.query_context_payload["queries"][0]["filters"] = []
self.query_context_payload["queries"][0]["extras"][
"having"
] = "COUNT(1) = 0) UNION ALL SELECT 'abc', 1--comment"
self.query_context_payload["queries"][0]["extras"]["having"] = (
"COUNT(1) = 0) UNION ALL SELECT 'abc', 1--comment"
)
rv = self.post_assert_metric(CHART_DATA_URI, self.query_context_payload, "data")
@@ -709,9 +712,9 @@ class TestPostChartDataApi(BaseTestChartDataApi):
self.query_context_payload["queries"][0]["filters"] = [
{"col": "gender", "op": "==", "val": "boy"}
]
self.query_context_payload["queries"][0]["extras"][
"where"
] = "('boy' = '{{ filter_values('gender', 'xyz' )[0] }}')"
self.query_context_payload["queries"][0]["extras"]["where"] = (
"('boy' = '{{ filter_values('gender', 'xyz' )[0] }}')"
)
rv = self.post_assert_metric(CHART_DATA_URI, self.query_context_payload, "data")
result = rv.json["result"][0]["query"]
if get_example_database().backend != "presto":
@@ -858,9 +861,9 @@ class TestPostChartDataApi(BaseTestChartDataApi):
"""
annotation_layers = []
self.query_context_payload["queries"][0][
"annotation_layers"
] = annotation_layers
self.query_context_payload["queries"][0]["annotation_layers"] = (
annotation_layers
)
# formula
annotation_layers.append(ANNOTATION_LAYERS[AnnotationType.FORMULA])
@@ -1171,7 +1174,7 @@ class TestGetChartDataApi(BaseTestChartDataApi):
orig_run = ChartDataCommand.run
def mock_run(self, **kwargs):
assert kwargs["force_cached"] == True
assert kwargs["force_cached"] is True # noqa: E712
# override force_cached to get result from DB
return orig_run(self, force_cached=False)
@@ -1217,7 +1220,7 @@ class TestGetChartDataApi(BaseTestChartDataApi):
orig_run = ChartDataCommand.run
def mock_run(self, **kwargs):
assert kwargs["force_cached"] == True
assert kwargs["force_cached"] is True # noqa: E712
# override force_cached to get result from DB
return orig_run(self, force_cached=False)
@@ -1382,7 +1385,7 @@ def test_data_cache_default_timeout(
def test_chart_cache_timeout(
load_energy_table_with_slice: list[Slice],
load_energy_table_with_slice: list[Slice], # noqa: F811
test_client,
login_as_admin,
physical_query_context,