Skip to content

Commit

Permalink
fix more PT004 PyDocStyle checks (apache#42841)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyl1u authored and kunaljubce committed Oct 13, 2024
1 parent e2b10f4 commit 506369a
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions tests/www/views/test_views_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ def acl_app(app):


@pytest.fixture(scope="module")
def reset_dagruns():
def _reset_dagruns():
"""Clean up stray garbage from other tests."""
clear_db_runs()


@pytest.fixture(autouse=True)
def init_dagruns(acl_app, reset_dagruns):
def _init_dagruns(acl_app, _reset_dagruns):
triggered_by_kwargs = {"triggered_by": DagRunTriggeredByType.TEST} if AIRFLOW_V_3_0_PLUS else {}
acl_app.dag_bag.get_dag("example_bash_operator").create_dagrun(
run_id=DEFAULT_RUN_ID,
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_dag_autocomplete_dag_display_name(client_all_dags):


@pytest.fixture
def setup_paused_dag():
def _setup_paused_dag():
"""Pause a DAG so we can test filtering."""
dag_to_pause = "example_branch_operator"
with create_session() as session:
Expand All @@ -339,7 +339,7 @@ def setup_paused_dag():
("paused", "example_branch_operator", "example_branch_labels"),
],
)
@pytest.mark.usefixtures("setup_paused_dag")
@pytest.mark.usefixtures("_setup_paused_dag")
def test_dag_autocomplete_status(client_all_dags, status, expected, unexpected):
with client_all_dags.session_transaction() as flask_session:
flask_session[FILTER_STATUS_COOKIE] = status
Expand Down
12 changes: 6 additions & 6 deletions tests/www/views/test_views_cluster_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ def examples_dag_bag():


@pytest.fixture(autouse=True)
def clean():
def _clean():
clear_db_runs()
yield
clear_db_runs()


# freeze time fixture so that it is applied before `make_dag_runs` is!
# freeze time fixture so that it is applied before `_make_dag_runs` is!
@pytest.fixture
def freeze_time_for_dagruns(time_machine):
def _freeze_time_for_dagruns(time_machine):
time_machine.move_to("2023-05-02T00:00:00+00:00", tick=False)


@pytest.fixture
def make_dag_runs(dag_maker, session, time_machine):
def _make_dag_runs(dag_maker, session, time_machine):
with dag_maker(
dag_id="test_dag_id",
serialized=True,
Expand Down Expand Up @@ -99,7 +99,7 @@ def make_dag_runs(dag_maker, session, time_machine):
session.flush()


@pytest.mark.usefixtures("freeze_time_for_dagruns", "make_dag_runs")
@pytest.mark.usefixtures("_freeze_time_for_dagruns", "_make_dag_runs")
def test_historical_metrics_data(admin_client, session, time_machine):
resp = admin_client.get(
"/object/historical_metrics_data?start_date=2023-01-01T00:00&end_date=2023-08-02T00:00",
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_historical_metrics_data(admin_client, session, time_machine):
}


@pytest.mark.usefixtures("freeze_time_for_dagruns", "make_dag_runs")
@pytest.mark.usefixtures("_freeze_time_for_dagruns", "_make_dag_runs")
def test_historical_metrics_data_date_filters(admin_client, session):
resp = admin_client.get(
"/object/historical_metrics_data?start_date=2023-02-02T00:00&end_date=2023-06-02T00:00",
Expand Down
2 changes: 1 addition & 1 deletion tests/www/views/test_views_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def conn_with_extra() -> dict[str, Any]:


@pytest.fixture(autouse=True)
def clear_connections():
def _clear_connections():
with create_session() as session:
session.query(Connection).delete()

Expand Down
4 changes: 2 additions & 2 deletions tests/www/views/test_views_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def client_dr_without_dag_run_create(app):


@pytest.fixture(scope="module", autouse=True)
def init_blank_dagrun():
def _init_blank_dagrun():
"""Make sure there are no runs before we test anything.
This really shouldn't be needed, but tests elsewhere leave the db dirty.
Expand All @@ -104,7 +104,7 @@ def init_blank_dagrun():


@pytest.fixture(autouse=True)
def reset_dagrun():
def _reset_dagrun():
yield
with create_session() as session:
session.query(DagRun).delete()
Expand Down
2 changes: 1 addition & 1 deletion tests/www/views/test_views_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class TestDatasetEndpoint:
@pytest.fixture(autouse=True)
def cleanup(self):
def _cleanup(self):
clear_db_assets()
yield
clear_db_assets()
Expand Down
2 changes: 1 addition & 1 deletion tests/www/views/test_views_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def dagruns(bash_dag, xcom_dag):


@pytest.fixture(autouse=True)
def clean_db():
def _clean_db():
clear_db_variables()
yield
clear_db_variables()
Expand Down
6 changes: 3 additions & 3 deletions tests/www/views/test_views_extra_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def dag_run(create_dag_run, session):


@pytest.fixture(scope="module", autouse=True)
def patched_app(app, dag):
def _patched_app(app, dag):
with mock.patch.object(app, "dag_bag") as mock_dag_bag:
mock_dag_bag.get_dag.return_value = dag
yield
Expand All @@ -123,7 +123,7 @@ def task_3(dag):


@pytest.fixture(scope="module", autouse=True)
def init_blank_task_instances():
def _init_blank_task_instances():
"""Make sure there are no runs before we test anything.
This really shouldn't be needed, but tests elsewhere leave the db dirty.
Expand All @@ -132,7 +132,7 @@ def init_blank_task_instances():


@pytest.fixture(autouse=True)
def reset_task_instances():
def _reset_task_instances():
yield
clear_db_runs()

Expand Down
6 changes: 3 additions & 3 deletions tests/www/views/test_views_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def examples_dag_bag():


@pytest.fixture(autouse=True)
def clean():
def _clean():
clear_db_runs()
clear_db_assets()
yield
Expand Down Expand Up @@ -187,11 +187,11 @@ def test_grid_data_filtered_on_run_type_and_run_state(admin_client, dag_with_run

# Create this as a fixture so that it is applied before the `dag_with_runs` fixture is!
@pytest.fixture
def freeze_time_for_dagruns(time_machine):
def _freeze_time_for_dagruns(time_machine):
time_machine.move_to("2022-01-02T00:00:00+00:00", tick=False)


@pytest.mark.usefixtures("freeze_time_for_dagruns")
@pytest.mark.usefixtures("_freeze_time_for_dagruns")
def test_one_run(admin_client, dag_with_runs: list[DagRun], session):
"""
Test a DAG with complex interaction of states:
Expand Down
38 changes: 19 additions & 19 deletions tests/www/views/test_views_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def clean_db():


@pytest.fixture(autouse=True)
def setup():
def _setup():
clean_db()
yield
clean_db()
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_home(capture_templates, admin_client):


@mock.patch("airflow.www.views.AirflowBaseView.render_template")
def test_home_dags_count(render_template_mock, admin_client, working_dags, session):
def test_home_dags_count(render_template_mock, admin_client, _working_dags, session):
from sqlalchemy import update

from airflow.models.dag import DagModel
Expand Down Expand Up @@ -204,7 +204,7 @@ def _process_file(file_path):


@pytest.fixture
def working_dags(tmp_path):
def _working_dags(tmp_path):
dag_contents_template = "from airflow import DAG\ndag = DAG('{}', schedule=None, tags=['{}'])"
for dag_id, tag in zip(TEST_FILTER_DAG_IDS, TEST_TAGS):
path = tmp_path / f"{dag_id}.py"
Expand All @@ -213,7 +213,7 @@ def working_dags(tmp_path):


@pytest.fixture
def working_dags_with_read_perm(tmp_path):
def _working_dags_with_read_perm(tmp_path):
dag_contents_template = "from airflow import DAG\ndag = DAG('{}', schedule=None, tags=['{}'])"
dag_contents_template_with_read_perm = (
"from airflow import DAG\ndag = DAG('{}', schedule=None, tags=['{}'], "
Expand All @@ -229,7 +229,7 @@ def working_dags_with_read_perm(tmp_path):


@pytest.fixture
def working_dags_with_edit_perm(tmp_path):
def _working_dags_with_edit_perm(tmp_path):
dag_contents_template = "from airflow import DAG\ndag = DAG('{}', schedule=None, tags=['{}'])"
dag_contents_template_with_read_perm = (
"from airflow import DAG\ndag = DAG('{}', schedule=None, tags=['{}'], "
Expand All @@ -245,23 +245,23 @@ def working_dags_with_edit_perm(tmp_path):


@pytest.fixture
def broken_dags(tmp_path, working_dags):
def _broken_dags(tmp_path, _working_dags):
for dag_id in TEST_FILTER_DAG_IDS:
path = tmp_path / f"{dag_id}.py"
path.write_text("airflow DAG")
_process_file(path)


@pytest.fixture
def broken_dags_with_read_perm(tmp_path, working_dags_with_read_perm):
def _broken_dags_with_read_perm(tmp_path, _working_dags_with_read_perm):
for dag_id in TEST_FILTER_DAG_IDS:
path = tmp_path / f"{dag_id}.py"
path.write_text("airflow DAG")
_process_file(path)


@pytest.fixture
def broken_dags_after_working(tmp_path):
def _broken_dags_after_working(tmp_path):
# First create and process a DAG file that works
path = tmp_path / "all_in_one.py"
contents = "from airflow import DAG\n"
Expand All @@ -275,7 +275,7 @@ def broken_dags_after_working(tmp_path):
_process_file(path)


def test_home_filter_tags(working_dags, admin_client):
def test_home_filter_tags(_working_dags, admin_client):
with admin_client:
admin_client.get("home?tags=example&tags=data", follow_redirects=True)
assert "example,data" == flask.session[FILTER_TAGS_COOKIE]
Expand All @@ -284,15 +284,15 @@ def test_home_filter_tags(working_dags, admin_client):
assert flask.session[FILTER_TAGS_COOKIE] is None


def test_home_importerrors(broken_dags, user_client):
def test_home_importerrors(_broken_dags, user_client):
# Users with "can read on DAGs" gets all DAG import errors
resp = user_client.get("home", follow_redirects=True)
check_content_in_response("Import Errors", resp)
for dag_id in TEST_FILTER_DAG_IDS:
check_content_in_response(f"/{dag_id}.py", resp)


def test_home_no_importerrors_perm(broken_dags, client_no_importerror):
def test_home_no_importerrors_perm(_broken_dags, client_no_importerror):
# Users without "can read on import errors" don't see any import errors
resp = client_no_importerror.get("home", follow_redirects=True)
check_content_not_in_response("Import Errors", resp)
Expand All @@ -310,7 +310,7 @@ def test_home_no_importerrors_perm(broken_dags, client_no_importerror):
"home?lastrun=all_states",
],
)
def test_home_importerrors_filtered_singledag_user(broken_dags_with_read_perm, client_single_dag, page):
def test_home_importerrors_filtered_singledag_user(_broken_dags_with_read_perm, client_single_dag, page):
# Users that can only see certain DAGs get a filtered list of import errors
resp = client_single_dag.get(page, follow_redirects=True)
check_content_in_response("Import Errors", resp)
Expand All @@ -322,7 +322,7 @@ def test_home_importerrors_filtered_singledag_user(broken_dags_with_read_perm, c
check_content_not_in_response(f"/{dag_id}.py", resp)


def test_home_importerrors_missing_read_on_all_dags_in_file(broken_dags_after_working, client_single_dag):
def test_home_importerrors_missing_read_on_all_dags_in_file(_broken_dags_after_working, client_single_dag):
# If a user doesn't have READ on all DAGs in a file, that files traceback is redacted
resp = client_single_dag.get("home", follow_redirects=True)
check_content_in_response("Import Errors", resp)
Expand All @@ -333,14 +333,14 @@ def test_home_importerrors_missing_read_on_all_dags_in_file(broken_dags_after_wo
check_content_in_response("REDACTED", resp)


def test_home_dag_list(working_dags, user_client):
def test_home_dag_list(_working_dags, user_client):
# Users with "can read on DAGs" gets all DAGs
resp = user_client.get("home", follow_redirects=True)
for dag_id in TEST_FILTER_DAG_IDS:
check_content_in_response(f"dag_id={dag_id}", resp)


def test_home_dag_list_filtered_singledag_user(working_dags_with_read_perm, client_single_dag):
def test_home_dag_list_filtered_singledag_user(_working_dags_with_read_perm, client_single_dag):
# Users that can only see certain DAGs get a filtered list
resp = client_single_dag.get("home", follow_redirects=True)
# They can see the first DAG
Expand All @@ -350,15 +350,15 @@ def test_home_dag_list_filtered_singledag_user(working_dags_with_read_perm, clie
check_content_not_in_response(f"dag_id={dag_id}", resp)


def test_home_dag_list_search(working_dags, user_client):
def test_home_dag_list_search(_working_dags, user_client):
resp = user_client.get("home?search=filter_test", follow_redirects=True)
check_content_in_response("dag_id=filter_test_1", resp)
check_content_in_response("dag_id=filter_test_2", resp)
check_content_not_in_response("dag_id=filter.test", resp)
check_content_not_in_response("dag_id=a_first_dag_id_asc", resp)


def test_home_dag_edit_permissions(capture_templates, working_dags_with_edit_perm, client_single_dag_edit):
def test_home_dag_edit_permissions(capture_templates, _working_dags_with_edit_perm, client_single_dag_edit):
with capture_templates() as templates:
client_single_dag_edit.get("home", follow_redirects=True)

Expand Down Expand Up @@ -446,7 +446,7 @@ def test_dashboard_flash_messages_type(user_client):
],
ids=["no_order_provided", "ascending_order_on_dag_id", "descending_order_on_dag_id"],
)
def test_sorting_home_view(url, lower_key, greater_key, user_client, working_dags):
def test_sorting_home_view(url, lower_key, greater_key, user_client, _working_dags):
resp = user_client.get(url, follow_redirects=True)
resp_html = resp.data.decode("utf-8")
lower_index = resp_html.find(lower_key)
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_analytics_pixel(user_client, is_enabled, should_have_pixel):
],
)
def test_filter_cookie_eval(
working_dags,
_working_dags,
admin_client,
url,
filter_tags_cookie_val,
Expand Down
2 changes: 1 addition & 1 deletion tests/www/views/test_views_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def factory():


@pytest.fixture(autouse=True)
def reset_modules_after_every_test(backup_modules):
def _reset_modules_after_every_test(backup_modules):
yield
# Remove any new modules imported during the test run.
# This lets us import the same source files for more than one test.
Expand Down
2 changes: 1 addition & 1 deletion tests/www/views/test_views_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


@pytest.fixture(autouse=True)
def clear_pools():
def _clear_pools():
with create_session() as session:
session.query(Pool).delete()

Expand Down
4 changes: 2 additions & 2 deletions tests/www/views/test_views_rendered.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def task_secret(dag):


@pytest.fixture(scope="module", autouse=True)
def init_blank_db():
def _init_blank_db():
"""Make sure there are no runs before we test anything.
This really shouldn't be needed, but tests elsewhere leave the db dirty.
Expand All @@ -130,7 +130,7 @@ def init_blank_db():


@pytest.fixture(autouse=True)
def reset_db(dag, task1, task2, task3, task4, task_secret):
def _reset_db(dag, task1, task2, task3, task4, task_secret):
yield
clear_db_dags()
clear_db_runs()
Expand Down

0 comments on commit 506369a

Please sign in to comment.