Skip to content

Commit b7819d9

Browse files
authored
python: assert actual == expected ordering (#36980)
1 parent 6fa6f69 commit b7819d9

36 files changed

+122
-122
lines changed

airbyte-cdk/python/unit_tests/connector_builder/test_message_grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def test_read_stream_returns_error_if_stream_does_not_exist() -> None:
543543
source=mock_source, config=full_config, configured_catalog=create_configured_catalog("not_in_manifest")
544544
)
545545

546-
assert 1 == len(actual_response.logs)
546+
assert len(actual_response.logs) == 1
547547
assert "Traceback" in actual_response.logs[0].message
548548
assert "ERROR" in actual_response.logs[0].level
549549

airbyte-cdk/python/unit_tests/destinations/test_destination.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_run_spec(self, mocker, destination: Destination):
157157
destination.spec.assert_called_once() # type: ignore
158158

159159
# verify the output of spec was returned
160-
assert _wrapped(expected_spec) == spec_message
160+
assert spec_message == _wrapped(expected_spec)
161161

162162
def test_run_check(self, mocker, destination: Destination, tmp_path):
163163
file_path = tmp_path / "config.json"
@@ -183,7 +183,7 @@ def test_run_check(self, mocker, destination: Destination, tmp_path):
183183
validate_mock.assert_called_with(dummy_config, spec_msg)
184184

185185
# verify output was correct
186-
assert _wrapped(expected_check_result) == returned_check_result
186+
assert returned_check_result == _wrapped(expected_check_result)
187187

188188
def test_run_write(self, mocker, destination: Destination, tmp_path, monkeypatch):
189189
config_path, dummy_config = tmp_path / "config.json", {"user": "sherif"}
@@ -235,7 +235,7 @@ def test_run_write(self, mocker, destination: Destination, tmp_path, monkeypatch
235235
validate_mock.assert_called_with(dummy_config, spec_msg)
236236

237237
# verify output was correct
238-
assert expected_write_result == returned_write_result
238+
assert returned_write_result == expected_write_result
239239

240240
@pytest.mark.parametrize("args", [{}, {"command": "fake"}])
241241
def test_run_cmd_with_incorrect_args_fails(self, args, destination: Destination):

airbyte-cdk/python/unit_tests/sources/declarative/datetime/test_datetime_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
def test_parse_date(test_name, input_date, date_format, expected_output_date):
4242
parser = DatetimeParser()
4343
output_date = parser.parse(input_date, date_format)
44-
assert expected_output_date == output_date
44+
assert output_date == expected_output_date
4545

4646

4747
@pytest.mark.parametrize(
@@ -56,4 +56,4 @@ def test_parse_date(test_name, input_date, date_format, expected_output_date):
5656
def test_format_datetime(test_name, input_dt, datetimeformat, expected_output):
5757
parser = DatetimeParser()
5858
output_date = parser.format(input_dt, datetimeformat)
59-
assert expected_output == output_date
59+
assert output_date == expected_output

airbyte-cdk/python/unit_tests/sources/declarative/incremental/test_datetime_based_cursor.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ def test_request_option(test_name, inject_into, field_name, expected_req_params,
541541
parameters={},
542542
)
543543
stream_slice = {"start_time": "2021-01-01T00:00:00.000000+0000", "end_time": "2021-01-04T00:00:00.000000+0000"}
544-
assert expected_req_params == slicer.get_request_params(stream_slice=stream_slice)
545-
assert expected_headers == slicer.get_request_headers(stream_slice=stream_slice)
546-
assert expected_body_json == slicer.get_request_body_json(stream_slice=stream_slice)
547-
assert expected_body_data == slicer.get_request_body_data(stream_slice=stream_slice)
544+
assert slicer.get_request_params(stream_slice=stream_slice) == expected_req_params
545+
assert slicer.get_request_headers(stream_slice=stream_slice) == expected_headers
546+
assert slicer.get_request_body_json(stream_slice=stream_slice) == expected_body_json
547+
assert slicer.get_request_body_data(stream_slice=stream_slice) == expected_body_data
548548

549549

550550
@pytest.mark.parametrize(
@@ -607,7 +607,7 @@ def test_parse_date_legacy_merge_datetime_format_in_cursor_datetime_format(
607607
parameters={},
608608
)
609609
output_date = slicer.parse_date(input_date)
610-
assert expected_output_date == output_date
610+
assert output_date == expected_output_date
611611

612612

613613
@pytest.mark.parametrize(
@@ -674,7 +674,7 @@ def test_format_datetime(test_name, input_dt, datetimeformat, datetimeformat_gra
674674
)
675675

676676
output_date = slicer._format_datetime(input_dt)
677-
assert expected_output == output_date
677+
assert output_date == expected_output
678678

679679

680680
def test_step_but_no_cursor_granularity():

airbyte-cdk/python/unit_tests/sources/declarative/partition_routers/test_list_partition_router.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def test_request_option(request_option, expected_req_params, expected_headers, e
9595
)
9696
stream_slice = {cursor_field: "customer"}
9797

98-
assert expected_req_params == partition_router.get_request_params(stream_slice=stream_slice)
99-
assert expected_headers == partition_router.get_request_headers(stream_slice=stream_slice)
100-
assert expected_body_json == partition_router.get_request_body_json(stream_slice=stream_slice)
101-
assert expected_body_data == partition_router.get_request_body_data(stream_slice=stream_slice)
98+
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_req_params
99+
assert partition_router.get_request_headers(stream_slice=stream_slice) == expected_headers
100+
assert partition_router.get_request_body_json(stream_slice=stream_slice) == expected_body_json
101+
assert partition_router.get_request_body_data(stream_slice=stream_slice) == expected_body_data
102102

103103

104104
@pytest.mark.parametrize(
@@ -139,7 +139,7 @@ def test_request_options_interpolation(field_name_interpolation: str, expected_r
139139
)
140140
stream_slice = {cursor_field: "customer"}
141141

142-
assert expected_request_params == partition_router.get_request_params(stream_slice=stream_slice)
142+
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_request_params
143143

144144

145145
def test_request_option_before_updating_cursor():

airbyte-cdk/python/unit_tests/sources/declarative/partition_routers/test_substream_partition_router.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ def test_request_option(
295295
)
296296
stream_slice = {"first_stream_id": "1234", "second_stream_id": "4567"}
297297

298-
assert expected_req_params == partition_router.get_request_params(stream_slice=stream_slice)
299-
assert expected_headers == partition_router.get_request_headers(stream_slice=stream_slice)
300-
assert expected_body_json == partition_router.get_request_body_json(stream_slice=stream_slice)
301-
assert expected_body_data == partition_router.get_request_body_data(stream_slice=stream_slice)
298+
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_req_params
299+
assert partition_router.get_request_headers(stream_slice=stream_slice) == expected_headers
300+
assert partition_router.get_request_body_json(stream_slice=stream_slice) == expected_body_json
301+
assert partition_router.get_request_body_data(stream_slice=stream_slice) == expected_body_data
302302

303303

304304
@pytest.mark.parametrize(
@@ -353,7 +353,7 @@ def test_request_params_interpolation_for_parent_stream(
353353
)
354354
stream_slice = {"first_stream_id": "1234", "second_stream_id": "4567"}
355355

356-
assert expected_request_params == partition_router.get_request_params(stream_slice=stream_slice)
356+
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_request_params
357357

358358

359359
def test_given_record_is_airbyte_message_when_stream_slices_then_use_record_data():

airbyte-cdk/python/unit_tests/sources/declarative/requesters/paginators/test_cursor_pagination_strategy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_cursor_pagination_strategy(test_name, template_string, stop_condition,
6161
last_records = [{"id": 0, "more_records": True}, {"id": 1, "more_records": True}]
6262

6363
token = strategy.next_page_token(response, last_records)
64-
assert expected_token == token
64+
assert token == expected_token
6565
assert page_size == strategy.get_page_size()
6666

6767

airbyte-cdk/python/unit_tests/sources/declarative/requesters/paginators/test_offset_increment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def test_offset_increment_paginator_strategy(page_size, parameters, last_records
3131
response._content = json.dumps(response_body).encode("utf-8")
3232

3333
next_page_token = paginator_strategy.next_page_token(response, last_records)
34-
assert expected_next_page_token == next_page_token
35-
assert expected_offset == paginator_strategy._offset
34+
assert next_page_token == expected_next_page_token
35+
assert paginator_strategy._offset == expected_offset
3636

3737
paginator_strategy.reset()
3838
assert 0 == paginator_strategy._offset

airbyte-cdk/python/unit_tests/sources/declarative/requesters/paginators/test_page_increment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def test_page_increment_paginator_strategy(page_size, start_from, last_records,
3333
response._content = json.dumps(response_body).encode("utf-8")
3434

3535
next_page_token = paginator_strategy.next_page_token(response, last_records)
36-
assert expected_next_page_token == next_page_token
37-
assert expected_offset == paginator_strategy._page
36+
assert next_page_token == expected_next_page_token
37+
assert paginator_strategy._page == expected_offset
3838

3939
paginator_strategy.reset()
4040
assert start_from == paginator_strategy._page

airbyte-cdk/python/unit_tests/sources/declarative/retrievers/test_simple_retriever.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_get_request_options_from_pagination(test_name, paginator_mapping, strea
219219
for _, method in request_option_type_to_method.items():
220220
if expected_mapping is not None:
221221
actual_mapping = method(None, None, None)
222-
assert expected_mapping == actual_mapping
222+
assert actual_mapping == expected_mapping
223223
else:
224224
try:
225225
method(None, None, None)
@@ -264,7 +264,7 @@ def test_get_request_headers(test_name, paginator_mapping, expected_mapping):
264264
for _, method in request_option_type_to_method.items():
265265
if expected_mapping:
266266
actual_mapping = method(None, None, None)
267-
assert expected_mapping == actual_mapping
267+
assert actual_mapping == expected_mapping
268268
else:
269269
try:
270270
method(None, None, None)
@@ -310,7 +310,7 @@ def test_ignore_stream_slicer_parameters_on_paginated_requests(test_name, pagina
310310

311311
for _, method in request_option_type_to_method.items():
312312
actual_mapping = method(None, None, next_page_token={"next_page_token": "1000"})
313-
assert expected_mapping == actual_mapping
313+
assert actual_mapping == expected_mapping
314314

315315

316316
@pytest.mark.parametrize(
@@ -345,7 +345,7 @@ def test_request_body_data(test_name, slicer_body_data, paginator_body_data, exp
345345

346346
if expected_body_data:
347347
actual_body_data = retriever._request_body_data(None, None, None)
348-
assert expected_body_data == actual_body_data
348+
assert actual_body_data == expected_body_data
349349
else:
350350
try:
351351
retriever._request_body_data(None, None, None)
@@ -380,7 +380,7 @@ def test_path(test_name, requester_path, paginator_path, expected_path):
380380
)
381381

382382
actual_path = retriever._paginator_path()
383-
assert expected_path == actual_path
383+
assert actual_path == expected_path
384384

385385

386386
def test_limit_stream_slices():

airbyte-cdk/python/unit_tests/sources/declarative/stream_slicers/test_cartesian_product_stream_slicer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ def test_request_option(
191191
)
192192
stream_slice = {"owner_resource": "customer", "repository": "airbyte"}
193193

194-
assert expected_req_params == slicer.get_request_params(stream_slice=stream_slice)
195-
assert expected_headers == slicer.get_request_headers(stream_slice=stream_slice)
196-
assert expected_body_json == slicer.get_request_body_json(stream_slice=stream_slice)
197-
assert expected_body_data == slicer.get_request_body_data(stream_slice=stream_slice)
194+
assert slicer.get_request_params(stream_slice=stream_slice) == expected_req_params
195+
assert slicer.get_request_headers(stream_slice=stream_slice) == expected_headers
196+
assert slicer.get_request_body_json(stream_slice=stream_slice) == expected_body_json
197+
assert slicer.get_request_body_data(stream_slice=stream_slice) == expected_body_data
198198

199199

200200
def test_request_option_before_updating_cursor():

airbyte-cdk/python/unit_tests/sources/declarative/test_manifest_declarative_source.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ def test_read_manifest_declarative_source(test_name, manifest, pages, expected_r
11231123
_stream_name = "Rates"
11241124
with patch.object(SimpleRetriever, "_fetch_next_page", side_effect=pages) as mock_retriever:
11251125
output_data = [message.record.data for message in _run_read(manifest, _stream_name) if message.record]
1126-
assert expected_records == output_data
1126+
assert output_data == expected_records
11271127
mock_retriever.assert_has_calls(expected_calls)
11281128

11291129

airbyte-cdk/python/unit_tests/sources/file_based/stream/concurrent/test_adapters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_get_error_display_message_no_display_message(self):
329329

330330
display_message = facade.get_error_display_message(e)
331331

332-
assert expected_display_message == display_message
332+
assert display_message == expected_display_message
333333

334334
def test_get_error_display_message_with_display_message(self):
335335
self._stream.get_error_display_message.return_value = "display_message"
@@ -341,7 +341,7 @@ def test_get_error_display_message_with_display_message(self):
341341

342342
display_message = facade.get_error_display_message(e)
343343

344-
assert expected_display_message == display_message
344+
assert display_message == expected_display_message
345345

346346

347347
@pytest.mark.parametrize(

airbyte-cdk/python/unit_tests/sources/file_based/stream/test_default_file_based_cursor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def test_add_file(files_to_add: List[RemoteFile], expected_start_time: List[date
111111

112112
for index, f in enumerate(files_to_add):
113113
cursor.add_file(f)
114-
assert expected_start_time[index] == cursor._compute_start_time()
115-
assert expected_state_dict == cursor.get_state()
114+
assert cursor._compute_start_time() == expected_start_time[index]
115+
assert cursor.get_state() == expected_state_dict
116116

117117

118118
@pytest.mark.parametrize(

airbyte-cdk/python/unit_tests/sources/file_based/test_scenarios.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _verify_state_record_counts(records: List[AirbyteMessage], states: List[Airb
143143
)
144144

145145
for stream, actual_count in actual_record_counts.items():
146-
assert state_record_count_sums.get(stream) == actual_count
146+
assert actual_count == state_record_count_sums.get(stream)
147147

148148
# We can have extra keys in state_record_count_sums if we processed a stream and reported 0 records
149149
extra_keys = state_record_count_sums.keys() - actual_record_counts.keys()

airbyte-cdk/python/unit_tests/sources/streams/concurrent/test_adapters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def test_get_error_display_message_no_display_message(self):
347347

348348
display_message = facade.get_error_display_message(e)
349349

350-
assert expected_display_message == display_message
350+
assert display_message == expected_display_message
351351

352352
def test_get_error_display_message_with_display_message(self):
353353
self._stream.get_error_display_message.return_value = "display_message"
@@ -359,7 +359,7 @@ def test_get_error_display_message_with_display_message(self):
359359

360360
display_message = facade.get_error_display_message(e)
361361

362-
assert expected_display_message == display_message
362+
assert display_message == expected_display_message
363363

364364

365365
@pytest.mark.parametrize(

airbyte-cdk/python/unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_handle_partition_done_no_other_streams_to_generate_partitions_for(self)
108108
messages = list(handler.on_partition_generation_completed(sentinel))
109109

110110
expected_messages = []
111-
assert expected_messages == messages
111+
assert messages == expected_messages
112112

113113
@freezegun.freeze_time("2020-01-01T00:00:00")
114114
def test_handle_last_stream_partition_done(self):
@@ -146,7 +146,7 @@ def test_handle_last_stream_partition_done(self):
146146
),
147147
),
148148
]
149-
assert expected_messages == messages
149+
assert messages == expected_messages
150150
assert in_order_validation_mock.mock_calls.index(
151151
call._another_stream.cursor.ensure_at_least_one_state_emitted
152152
) < in_order_validation_mock.mock_calls.index(call._message_repository.consume_queue)
@@ -223,7 +223,7 @@ def test_handle_on_partition_complete_sentinel_with_messages_from_repository(sel
223223
expected_messages = [
224224
AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=LogLevel.INFO, message="message emitted from the repository"))
225225
]
226-
assert expected_messages == messages
226+
assert messages == expected_messages
227227

228228
partition.close.assert_called_once()
229229

@@ -267,7 +267,7 @@ def test_handle_on_partition_complete_sentinel_yields_status_message_if_the_stre
267267
),
268268
)
269269
]
270-
assert expected_messages == messages
270+
assert messages == expected_messages
271271
self._a_closed_partition.close.assert_called_once()
272272

273273
@freezegun.freeze_time("2020-01-01T00:00:00")
@@ -294,7 +294,7 @@ def test_handle_on_partition_complete_sentinel_yields_no_status_message_if_the_s
294294
messages = list(handler.on_partition_complete_sentinel(sentinel))
295295

296296
expected_messages = []
297-
assert expected_messages == messages
297+
assert messages == expected_messages
298298
partition.close.assert_called_once()
299299

300300
@freezegun.freeze_time("2020-01-01T00:00:00")
@@ -331,7 +331,7 @@ def test_on_record_no_status_message_no_repository_messge(self):
331331
),
332332
)
333333
]
334-
assert expected_messages == messages
334+
assert messages == expected_messages
335335

336336
@freezegun.freeze_time("2020-01-01T00:00:00")
337337
def test_on_record_with_repository_messge(self):
@@ -381,7 +381,7 @@ def test_on_record_with_repository_messge(self):
381381
),
382382
AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=LogLevel.INFO, message="message emitted from the repository")),
383383
]
384-
assert expected_messages == messages
384+
assert messages == expected_messages
385385
assert handler._record_counter[_STREAM_NAME] == 2
386386

387387
@freezegun.freeze_time("2020-01-01T00:00:00")
@@ -423,7 +423,7 @@ def test_on_record_emits_status_message_on_first_record_no_repository_message(se
423423
),
424424
),
425425
]
426-
assert expected_messages == messages
426+
assert messages == expected_messages
427427

428428
@freezegun.freeze_time("2020-01-01T00:00:00")
429429
def test_on_record_emits_status_message_on_first_record_with_repository_message(self):
@@ -477,7 +477,7 @@ def test_on_record_emits_status_message_on_first_record_with_repository_message(
477477
),
478478
AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=LogLevel.INFO, message="message emitted from the repository")),
479479
]
480-
assert expected_messages == messages
480+
assert messages == expected_messages
481481

482482
@freezegun.freeze_time("2020-01-01T00:00:00")
483483
def test_on_exception_return_trace_message_and_on_stream_complete_return_stream_status(self):

0 commit comments

Comments
 (0)