Skip to content

Commit

Permalink
Remove unnecessary start of range from tests (apache#33861)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala authored Aug 29, 2023
1 parent 49d8864 commit f9e9222
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_mapped_task_instances_order(self, one_task_with_many_mapped_tis, sessio
assert response.status_code == 200
assert response.json["total_entries"] == 110
assert len(response.json["task_instances"]) == 100
assert list(range(0, 100)) == [ti["map_index"] for ti in response.json["task_instances"]]
assert list(range(100)) == [ti["map_index"] for ti in response.json["task_instances"]]

@provide_session
def test_mapped_task_instances_reverse_order(self, one_task_with_many_mapped_tis, session):
Expand All @@ -348,7 +348,7 @@ def test_mapped_task_instances_state_order(self, one_task_with_many_mapped_tis,
assert response.status_code == 200
assert response.json["total_entries"] == 110
assert len(response.json["task_instances"]) == 100
assert list(range(0, 5)) + list(range(25, 110)) + list(range(5, 15)) == [
assert list(range(5)) + list(range(25, 110)) + list(range(5, 15)) == [
ti["map_index"] for ti in response.json["task_instances"]
]

Expand Down
4 changes: 2 additions & 2 deletions tests/auth/managers/fab/cli_commands/test_user_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_find_user_exceptions(self, args, raise_match):
user_command._find_user(args)

def test_cli_list_users(self):
for i in range(0, 3):
for i in range(3):
args = self.parser.parse_args(
[
"users",
Expand All @@ -228,7 +228,7 @@ def test_cli_list_users(self):
with redirect_stdout(io.StringIO()) as stdout:
user_command.users_list(self.parser.parse_args(["users", "list"]))
stdout = stdout.getvalue()
for i in range(0, 3):
for i in range(3):
assert f"user{i}" in stdout

def test_cli_list_users_with_args(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/jobs/test_scheduler_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def test_execute_task_instances_limit(self, dag_maker):
def _create_dagruns():
dagrun = dag_maker.create_dagrun(run_type=DagRunType.SCHEDULED, state=State.RUNNING)
yield dagrun
for _ in range(0, 3):
for _ in range(3):
dagrun = dag_maker.create_dagrun_after(
dagrun,
run_type=DagRunType.SCHEDULED,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ def test_execute_task_instances_unlimited(self, dag_maker):
def _create_dagruns():
dagrun = dag_maker.create_dagrun(run_type=DagRunType.SCHEDULED, state=State.RUNNING)
yield dagrun
for _ in range(0, 19):
for _ in range(19):
dagrun = dag_maker.create_dagrun_after(
dagrun,
run_type=DagRunType.SCHEDULED,
Expand Down
14 changes: 7 additions & 7 deletions tests/models/test_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def test_dag_task_priority_weight_total(self):
# Default weight should be calculated using downstream descendants
with DAG("dag", start_date=DEFAULT_DATE, default_args={"owner": "owner1"}) as dag:
pipeline = [
[EmptyOperator(task_id=f"stage{i}.{j}", priority_weight=weight) for j in range(0, width)]
for i in range(0, depth)
[EmptyOperator(task_id=f"stage{i}.{j}", priority_weight=weight) for j in range(width)]
for i in range(depth)
]
for i, stage in enumerate(pipeline):
if i == 0:
Expand Down Expand Up @@ -371,9 +371,9 @@ def test_dag_task_priority_weight_total_using_upstream(self):
priority_weight=weight,
weight_rule=WeightRule.UPSTREAM,
)
for j in range(0, width)
for j in range(width)
]
for i in range(0, depth)
for i in range(depth)
]
for i, stage in enumerate(pipeline):
if i == 0:
Expand Down Expand Up @@ -404,9 +404,9 @@ def test_dag_task_priority_weight_total_using_absolute(self):
priority_weight=weight,
weight_rule=WeightRule.ABSOLUTE,
)
for j in range(0, width)
for j in range(width)
]
for i in range(0, depth)
for i in range(depth)
]
for i, stage in enumerate(pipeline):
if i == 0:
Expand Down Expand Up @@ -859,7 +859,7 @@ def test_dagtag_repr(self):

def test_bulk_write_to_db(self):
clear_db_dags()
dags = [DAG(f"dag-bulk-sync-{i}", start_date=DEFAULT_DATE, tags=["test-dag"]) for i in range(0, 4)]
dags = [DAG(f"dag-bulk-sync-{i}", start_date=DEFAULT_DATE, tags=["test-dag"]) for i in range(4)]

with assert_queries_count(5):
DAG.bulk_write_to_db(dags)
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/apache/hive/hooks/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_load_df_with_optional_parameters(self, mock_to_csv, mock_load_file):
bools = (True, False)
for create, recreate in itertools.product(bools, bools):
mock_load_file.reset_mock()
hook.load_df(df=pd.DataFrame({"c": range(0, 10)}), table="t", create=create, recreate=recreate)
hook.load_df(df=pd.DataFrame({"c": range(10)}), table="t", create=create, recreate=recreate)

assert mock_load_file.call_count == 1
kwargs = mock_load_file.call_args.kwargs
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/google/cloud/transfers/test_sql_to_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
]
mock_file.flush.assert_has_calls([mock.call(), mock.call(), mock.call(), mock.call()])
csv_calls = []
for i in range(0, 3):
for i in range(3):
csv_calls.append(
mock.call(
BUCKET,
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/microsoft/azure/hooks/test_asb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from airflow.providers.microsoft.azure.hooks.asb import AdminClientHook, MessageHook

MESSAGE = "Test Message"
MESSAGE_LIST = [f"{MESSAGE} {n}" for n in range(0, 10)]
MESSAGE_LIST = [f"{MESSAGE} {n}" for n in range(10)]


class TestAdminClientHook:
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/microsoft/azure/operators/test_asb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

QUEUE_NAME = "test_queue"
MESSAGE = "Test Message"
MESSAGE_LIST = [MESSAGE + " " + str(n) for n in range(0, 10)]
MESSAGE_LIST = [MESSAGE + " " + str(n) for n in range(10)]

OWNER_NAME = "airflow"
DAG_ID = "test_azure_service_bus_subscription"
Expand Down
2 changes: 1 addition & 1 deletion tests/sensors/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def run_duration():
for retry_number in range(1, 10)
]

for i in range(0, len(intervals) - 1):
for i in range(len(intervals) - 1):
# intervals should be increasing or equals
assert intervals[i] <= intervals[i + 1]
if poke_interval > 0:
Expand Down
4 changes: 2 additions & 2 deletions tests/sensors/test_external_task_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ def test_clear_overlapping_external_task_marker(dag_bag_head_tail, session):
dag: DAG = dag_bag_head_tail.get_dag("head_tail")

# "Run" 10 times.
for delta in range(0, 10):
for delta in range(10):
execution_date = DEFAULT_DATE + timedelta(days=delta)
dagrun = DagRun(
dag_id=dag.dag_id,
Expand Down Expand Up @@ -1497,7 +1497,7 @@ def test_clear_overlapping_external_task_marker_mapped_tasks(dag_bag_head_tail_m
dag: DAG = dag_bag_head_tail_mapped_tasks.get_dag("head_tail")

# "Run" 10 times.
for delta in range(0, 10):
for delta in range(10):
execution_date = DEFAULT_DATE + timedelta(days=delta)
dagrun = DagRun(
dag_id=dag.dag_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def execute_in_k8s_pod():
@task.kubernetes(image="python:3.8-slim-buster", namespace="default", in_cluster=False)
def print_pattern():
n = 5
for i in range(0, n):
for i in range(n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i + 1):
for j in range(i + 1):
# printing stars
print("* ", end="")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
CLIENT_ID = os.getenv("CLIENT_ID", "")
QUEUE_NAME = "sb_mgmt_queue_test"
MESSAGE = "Test Message"
MESSAGE_LIST = [f"{MESSAGE} {n}" for n in range(0, 10)]
MESSAGE_LIST = [f"{MESSAGE} {n}" for n in range(10)]
TOPIC_NAME = "sb_mgmt_topic_test"
SUBSCRIPTION_NAME = "sb_mgmt_subscription"

Expand Down
2 changes: 1 addition & 1 deletion tests/system/providers/snowflake/example_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
f"CREATE OR REPLACE TRANSIENT TABLE {SNOWFLAKE_SAMPLE_TABLE} (name VARCHAR(250), id INT);"
)
SQL_INSERT_STATEMENT = f"INSERT INTO {SNOWFLAKE_SAMPLE_TABLE} VALUES ('name', %(id)s)"
SQL_LIST = [SQL_INSERT_STATEMENT % {"id": n} for n in range(0, 10)]
SQL_LIST = [SQL_INSERT_STATEMENT % {"id": n} for n in range(10)]
SQL_MULTIPLE_STMTS = "; ".join(SQL_LIST)
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "example_snowflake"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/perf/perf_kit/repeat_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def monte_carlo(total=10000):
"""Monte Carlo"""
inside = 0

for _ in range(0, total):
for _ in range(total):
x_val = random.random() ** 2
y_val = random.random() ** 2
if math.sqrt(x_val + y_val) < 1:
Expand Down
2 changes: 1 addition & 1 deletion tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def check_generate_pages_html(
last_page = total_pages - 1

if current_page <= mid or total_pages < window:
pages = list(range(0, min(total_pages, window)))
pages = list(range(min(total_pages, window)))
elif mid < current_page < last_page - mid:
pages = list(range(current_page - mid, current_page + mid + 1))
else:
Expand Down

0 comments on commit f9e9222

Please sign in to comment.