Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,7 +302,7 @@ def test_run_command_daemon(
]
else:
assert mock_daemon.mock_calls == []
mock_setup_locations.mock_calls == []
assert mock_setup_locations.mock_calls == []
mock_pid_file.assert_not_called()
mock_open.assert_not_called()

Expand Down
6 changes: 3 additions & 3 deletions airflow-core/tests/unit/jobs/test_scheduler_job.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,7 +3743,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):

dr = dag_maker.create_dagrun(start_date=timezone.utcnow() - datetime.timedelta(days=1))
# check that next_dagrun is dr.logical_date
dag_maker.dag_model.next_dagrun == dr.logical_date
assert dag_maker.dag_model.next_dagrun == dr.logical_date
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, executors=[self.null_exec])

Expand DownExpand Up@@ -4600,7 +4600,7 @@ def test_verify_integrity_if_dag_changed(self, dag_maker):
dr = drs[0]

self.job_runner._schedule_dag_run(dag_run=dr, session=session)
len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
assert len(self.job_runner.scheduler_dag_bag.get_dag_for_run(dr, session).tasks) == 1
dag_version_1 = DagVersion.get_latest_version(dr.dag_id, session=session)
assert dr.dag_versions[-1].id == dag_version_1.id

Expand DownExpand Up@@ -5799,7 +5799,7 @@ def test_more_runs_are_not_created_when_max_active_runs_is_reached(self, dag_mak
dag_models = query.all()
self.job_runner._create_dag_runs(dag_models, session)
dr = session.scalars(select(DagRun)).one()
dr.state == DagRunState.QUEUED
assert dr.state == DagRunState.QUEUED
assert session.scalar(select(func.count()).select_from(DagRun)) == 1
assert dag_maker.dag_model.next_dagrun_create_after == DEFAULT_DATE + timedelta(days=2)
assert dag_maker.dag_model.next_dagrun == DEFAULT_DATE + timedelta(days=1)
Expand Down
2 changes: 1 addition & 1 deletion airflow-core/tests/unit/models/test_dag.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3567,7 +3567,7 @@ def test_get_flat_relative_ids_with_setup(self):
# now, we know that t1 is the teardown for s1, so now we know that s1 will be "torn down"
# by the time w4 runs, so we now know that w4 no longer requires s1, so when we clear w4,
# s1 will not also be cleared
self.cleared_downstream(w4) == {w4}
assert self.cleared_downstream(w4) == {w4}
assert set(w1.get_upstreams_only_setups_and_teardowns()) == {s1, t1}
assert self.cleared_downstream(w1) == {s1, w1, w2, w3, t1, w4}
assert self.cleared_upstream(w1) == {s1, w1, t1}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -935,9 +935,9 @@ def validate_deserialized_task(
if isinstance(task, MappedOperator):
# MappedOperator.operator_class now stores only minimal type information
# for memory efficiency (task_type and _operator_name).
serialized_task.operator_class["task_type"] == type(task).__name__
assert serialized_task.operator_class["task_type"] == task.operator_class.__name__
if isinstance(serialized_task.operator_class, DecoratedOperator):
serialized_task.operator_class["_operator_name"] == task._operator_name
assert serialized_task.operator_class["_operator_name"] == task._operator_name

# Serialization cleans up default values in partial_kwargs, this
# adds them back to both sides.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1600,7 +1600,7 @@ def test_airflow_local_settings_kerberos_sidecar(self, workers_values):
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)
jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"
assert jmespath.search("spec.containers[1].name", docs[0]) == "worker-kerberos"

assert {
"name": "config",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,7 +397,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 1

# Add more tasks to pending_jobs. This simulates tasks being scheduled by Airflow
Expand All@@ -417,7 +417,7 @@ def test_attempt_all_jobs_when_some_jobs_fail(self, _, mock_executor):
submit_job_args["containerOverrides"]["command"] = airflow_commands[i]
assert mock_executor.batch.submit_job.call_args_list[i].kwargs == submit_job_args
assert len(mock_executor.pending_jobs) == 1
mock_executor.pending_jobs[0].command == airflow_cmd1
assert mock_executor.pending_jobs[0].command == airflow_cmd1
assert len(mock_executor.active_workers.get_all_jobs()) == 3

airflow_commands.append(airflow_cmd1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,13 +174,20 @@ def test_customize_model_wait_combinations(
@mock.patch.object(BedrockHook, "get_waiter")
def test_ensure_unique_job_name(self, _, side_effect, ensure_unique_name, mock_conn, bedrock_hook):
mock_conn.create_model_customization_job.side_effect = side_effect
expected_call_count = len(side_effect) if ensure_unique_name else 1
self.operator.ensure_unique_job_name = ensure_unique_name
self.operator.wait_for_completion = False
expected_call_count = len(side_effect) if ensure_unique_name else 1

if not ensure_unique_name and any(isinstance(e, ClientError) for e in side_effect):
with pytest.raises(ClientError):
self.operator.execute({})
assert mock_conn.create_model_customization_job.call_count == expected_call_count
return

response = self.operator.execute({})

assert response == self.CUSTOMIZE_JOB_ARN
mock_conn.create_model_customization_job.call_count == expected_call_count
assert mock_conn.create_model_customization_job.call_count == expected_call_count
bedrock_hook.get_waiter.assert_not_called()
self.operator.defer.assert_not_called()

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,11 +78,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai
"applicationId": application_id,
"ResponseMetadata": {"HTTPStatusCode": 200},
}
mock_conn.get_application.side_effect = [
{"application": {"state": "CREATED"}},
{"application": {"state": "STARTED"}},
]

operator = EmrServerlessCreateApplicationOperator(
task_id=task_id,
release_label=release_label,
Expand DownExpand Up@@ -111,7 +106,6 @@ def test_execute_successfully_with_wait_for_completion(self, mock_conn, mock_wai

mock_conn.start_application.assert_called_once_with(applicationId=application_id)
assert id == application_id
mock_conn.get_application.call_count == 2
Comment thread
shahar1 marked this conversation as resolved.

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -234,7 +228,7 @@ def test_failed_create_application(self, mock_conn, mock_get_waiter):
type=job_type,
**config,
)
mock_conn.create_application.call_count == 2
assert mock_conn.create_application.call_count == 2

@mock.patch.object(EmrServerlessHook, "get_waiter")
@mock.patch.object(EmrServerlessHook, "conn")
Expand DownExpand Up@@ -823,7 +817,7 @@ def test_start_job_run_fail_on_wait_for_completion(self, mock_conn, mock_get_wai
assert "Serverless Job failed:" in str(ex_message.value)
default_name = operator.name

mock_conn.get_application.call_count == 2
assert mock_conn.get_application.call_count == 1
mock_conn.start_job_run.assert_called_once_with(
clientToken=client_request_token,
applicationId=application_id,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ def test_integer_fields_with_stopping_condition(self, _, __, ___, mock_desc):
(key3,) = key3_raw
assert sagemaker.config[key1][key2][key3] == int(sagemaker.config[key1][key2][key3])
else:
sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])
assert sagemaker.config[key1][key2] == int(sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_processing_job")
@mock.patch.object(SageMakerHook, "count_processing_jobs_by_name", return_value=0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ def test_integer_fields(self, _, mock_create_transform, __, ___, mock_desc):
(key3,) = key3_org
assert self.sagemaker.config[key1][key2][key3] == int(self.sagemaker.config[key1][key2][key3])
else:
self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])
assert self.sagemaker.config[key1][key2] == int(self.sagemaker.config[key1][key2])

@mock.patch.object(SageMakerHook, "describe_transform_job")
@mock.patch.object(SageMakerHook, "create_model")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ def test_wait_with_list_response(self, mock_sleep):
"MaxAttempts": 1,
},
)
mock_waiter.wait.call_count == 3
assert mock_waiter.wait.call_count == 3
mock_sleep.assert_called_with(123)

@mock.patch("time.sleep")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1639,7 +1639,7 @@ def test_revoke_task(self, mock_kube_dynamic_client, dag_maker, create_dummy_dag
assert not executor.has_task(task_instance=ti)
executor.kube_scheduler.patch_pod_revoked.assert_called_once()
executor.kube_scheduler.delete_pod.assert_called_once()
mock_kube_client.patch_namespaced_pod.calls[0] == []
mock_kube_client.patch_namespaced_pod.assert_not_called()
assert executor.running == set()

@pytest.mark.parametrize(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,7 +1303,7 @@ def test_rowcount(self, mock_get_client):
def test_fetchone(self, mock_next, mock_get_client):
bq_cursor = self.hook.get_cursor()
result = bq_cursor.fetchone()
mock_next.call_count == 1
assert mock_next.call_count == 1
assert mock_next.return_value == result

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_client")
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,15 @@
["102", "business", "2017-05-24"],
["103", "non-profit", "2018-10-01"],
]
OUTPUT_DATA = json.dumps(
EXPECTED_JSON_ROW = json.dumps(
{
"column_a": "convert_type_return_value",
"column_b": "convert_type_return_value",
"column_c": "convert_type_return_value",
}
).encode("utf-8")
},
sort_keys=True,
ensure_ascii=False,
)
SCHEMA_FILE = "schema_file.json"
APP_JSON = "application/json"

Expand DownExpand Up@@ -163,6 +165,7 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
mock_file.flush.reset_mock()
mock_upload.reset_mock()
mock_file.close.reset_mock()
mock_file.write.reset_mock()
cursor_mock.reset_mock()

cursor_mock.__iter__ = Mock(return_value=iter(INPUT_DATA))
Expand All@@ -183,14 +186,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3
mock_upload.assert_called_once_with(
BUCKET, FILENAME.format(0), TMP_FILE_NAME, mime_type=APP_JSON, gzip=False, metadata=None
)
Expand DownExpand Up@@ -227,14 +224,8 @@ def test_exec(self, mock_convert_type, mock_query, mock_upload, mock_writer, moc
}

mock_query.assert_called_once()
mock_file.write.call_args_list == [
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
mock.call(OUTPUT_DATA),
mock.call(b"\n"),
]
written = "".join(c.args[0] for c in mock_file.write.call_args_list)
assert written == (EXPECTED_JSON_ROW + "\n") * 3

mock_file.flush.assert_called_once()
mock_upload.assert_called_once_with(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,6 +601,7 @@ extend-select = [
"G", # flake8-logging-format rules
"LOG", # flake8-logging rules, most of them autofixable
"PT", # flake8-pytest-style rules
"B015", # Useless comparison: bare `a == b` is a no-op; prepend `assert` or remove
"TID25", # flake8-tidy-imports rules
"E", # pycodestyle rules
"W", # pycodestyle rules
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,7 +190,7 @@ def test_decr_with_rate_limit_works(self, mock_random, name):
assert mock_random.call_count == 2
# add() is called once in the initial stats.incr and once for the decr that passed the rate check.
self.map[full_name(name)].add.assert_has_calls(expected_calls)
self.map[full_name(name)].add.call_count == 2
assert self.map[full_name(name)].add.call_count == 2

def test_gauge_new_metric(self, name):
self.stats.gauge(name, value=1)
Expand All@@ -205,7 +205,7 @@ def test_gauge_new_metric_with_tags(self, name):
self.stats.gauge(name, value=1, tags=tags)

self.meter.get_meter().create_gauge.assert_called_once_with(name=full_name(name))
self.map[key].attributes == tags
assert self.map[key].attributes == tags

def test_gauge_existing_metric(self, name):
self.stats.gauge(name, value=1)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/tests/task_sdk/definitions/test_taskgroup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -774,8 +774,8 @@ def test_mapped_task_group_id_prefix_task_id():
assert t1.task_id == "t1"
assert t2.task_id == "g.t2"

dag.get_task("t1") == t1
dag.get_task("g.t2") == t2
assert dag.get_task("t1") == t1
assert dag.get_task("g.t2") == t2


def test_pass_taskgroup_output_to_task():
Expand Down
Loading