Skip to content

Commit

Permalink
python: assert actual == expected ordering (#36980)
Browse files Browse the repository at this point in the history
  • Loading branch information
erohmensing committed Apr 11, 2024
1 parent 6fa6f69 commit b7819d9
Show file tree
Hide file tree
Showing 36 changed files with 122 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def test_read_stream_returns_error_if_stream_does_not_exist() -> None:
source=mock_source, config=full_config, configured_catalog=create_configured_catalog("not_in_manifest")
)

assert 1 == len(actual_response.logs)
assert len(actual_response.logs) == 1
assert "Traceback" in actual_response.logs[0].message
assert "ERROR" in actual_response.logs[0].level

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_run_spec(self, mocker, destination: Destination):
destination.spec.assert_called_once() # type: ignore

# verify the output of spec was returned
assert _wrapped(expected_spec) == spec_message
assert spec_message == _wrapped(expected_spec)

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

# verify output was correct
assert _wrapped(expected_check_result) == returned_check_result
assert returned_check_result == _wrapped(expected_check_result)

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

# verify output was correct
assert expected_write_result == returned_write_result
assert returned_write_result == expected_write_result

@pytest.mark.parametrize("args", [{}, {"command": "fake"}])
def test_run_cmd_with_incorrect_args_fails(self, args, destination: Destination):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
def test_parse_date(test_name, input_date, date_format, expected_output_date):
parser = DatetimeParser()
output_date = parser.parse(input_date, date_format)
assert expected_output_date == output_date
assert output_date == expected_output_date


@pytest.mark.parametrize(
Expand All @@ -56,4 +56,4 @@ def test_parse_date(test_name, input_date, date_format, expected_output_date):
def test_format_datetime(test_name, input_dt, datetimeformat, expected_output):
parser = DatetimeParser()
output_date = parser.format(input_dt, datetimeformat)
assert expected_output == output_date
assert output_date == expected_output
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,10 @@ def test_request_option(test_name, inject_into, field_name, expected_req_params,
parameters={},
)
stream_slice = {"start_time": "2021-01-01T00:00:00.000000+0000", "end_time": "2021-01-04T00:00:00.000000+0000"}
assert expected_req_params == slicer.get_request_params(stream_slice=stream_slice)
assert expected_headers == slicer.get_request_headers(stream_slice=stream_slice)
assert expected_body_json == slicer.get_request_body_json(stream_slice=stream_slice)
assert expected_body_data == slicer.get_request_body_data(stream_slice=stream_slice)
assert slicer.get_request_params(stream_slice=stream_slice) == expected_req_params
assert slicer.get_request_headers(stream_slice=stream_slice) == expected_headers
assert slicer.get_request_body_json(stream_slice=stream_slice) == expected_body_json
assert slicer.get_request_body_data(stream_slice=stream_slice) == expected_body_data


@pytest.mark.parametrize(
Expand Down Expand Up @@ -607,7 +607,7 @@ def test_parse_date_legacy_merge_datetime_format_in_cursor_datetime_format(
parameters={},
)
output_date = slicer.parse_date(input_date)
assert expected_output_date == output_date
assert output_date == expected_output_date


@pytest.mark.parametrize(
Expand Down Expand Up @@ -674,7 +674,7 @@ def test_format_datetime(test_name, input_dt, datetimeformat, datetimeformat_gra
)

output_date = slicer._format_datetime(input_dt)
assert expected_output == output_date
assert output_date == expected_output


def test_step_but_no_cursor_granularity():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def test_request_option(request_option, expected_req_params, expected_headers, e
)
stream_slice = {cursor_field: "customer"}

assert expected_req_params == partition_router.get_request_params(stream_slice=stream_slice)
assert expected_headers == partition_router.get_request_headers(stream_slice=stream_slice)
assert expected_body_json == partition_router.get_request_body_json(stream_slice=stream_slice)
assert expected_body_data == partition_router.get_request_body_data(stream_slice=stream_slice)
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_req_params
assert partition_router.get_request_headers(stream_slice=stream_slice) == expected_headers
assert partition_router.get_request_body_json(stream_slice=stream_slice) == expected_body_json
assert partition_router.get_request_body_data(stream_slice=stream_slice) == expected_body_data


@pytest.mark.parametrize(
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_request_options_interpolation(field_name_interpolation: str, expected_r
)
stream_slice = {cursor_field: "customer"}

assert expected_request_params == partition_router.get_request_params(stream_slice=stream_slice)
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_request_params


def test_request_option_before_updating_cursor():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ def test_request_option(
)
stream_slice = {"first_stream_id": "1234", "second_stream_id": "4567"}

assert expected_req_params == partition_router.get_request_params(stream_slice=stream_slice)
assert expected_headers == partition_router.get_request_headers(stream_slice=stream_slice)
assert expected_body_json == partition_router.get_request_body_json(stream_slice=stream_slice)
assert expected_body_data == partition_router.get_request_body_data(stream_slice=stream_slice)
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_req_params
assert partition_router.get_request_headers(stream_slice=stream_slice) == expected_headers
assert partition_router.get_request_body_json(stream_slice=stream_slice) == expected_body_json
assert partition_router.get_request_body_data(stream_slice=stream_slice) == expected_body_data


@pytest.mark.parametrize(
Expand Down Expand Up @@ -353,7 +353,7 @@ def test_request_params_interpolation_for_parent_stream(
)
stream_slice = {"first_stream_id": "1234", "second_stream_id": "4567"}

assert expected_request_params == partition_router.get_request_params(stream_slice=stream_slice)
assert partition_router.get_request_params(stream_slice=stream_slice) == expected_request_params


def test_given_record_is_airbyte_message_when_stream_slices_then_use_record_data():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_cursor_pagination_strategy(test_name, template_string, stop_condition,
last_records = [{"id": 0, "more_records": True}, {"id": 1, "more_records": True}]

token = strategy.next_page_token(response, last_records)
assert expected_token == token
assert token == expected_token
assert page_size == strategy.get_page_size()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_offset_increment_paginator_strategy(page_size, parameters, last_records
response._content = json.dumps(response_body).encode("utf-8")

next_page_token = paginator_strategy.next_page_token(response, last_records)
assert expected_next_page_token == next_page_token
assert expected_offset == paginator_strategy._offset
assert next_page_token == expected_next_page_token
assert paginator_strategy._offset == expected_offset

paginator_strategy.reset()
assert 0 == paginator_strategy._offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_page_increment_paginator_strategy(page_size, start_from, last_records,
response._content = json.dumps(response_body).encode("utf-8")

next_page_token = paginator_strategy.next_page_token(response, last_records)
assert expected_next_page_token == next_page_token
assert expected_offset == paginator_strategy._page
assert next_page_token == expected_next_page_token
assert paginator_strategy._page == expected_offset

paginator_strategy.reset()
assert start_from == paginator_strategy._page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_get_request_options_from_pagination(test_name, paginator_mapping, strea
for _, method in request_option_type_to_method.items():
if expected_mapping is not None:
actual_mapping = method(None, None, None)
assert expected_mapping == actual_mapping
assert actual_mapping == expected_mapping
else:
try:
method(None, None, None)
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_get_request_headers(test_name, paginator_mapping, expected_mapping):
for _, method in request_option_type_to_method.items():
if expected_mapping:
actual_mapping = method(None, None, None)
assert expected_mapping == actual_mapping
assert actual_mapping == expected_mapping
else:
try:
method(None, None, None)
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_ignore_stream_slicer_parameters_on_paginated_requests(test_name, pagina

for _, method in request_option_type_to_method.items():
actual_mapping = method(None, None, next_page_token={"next_page_token": "1000"})
assert expected_mapping == actual_mapping
assert actual_mapping == expected_mapping


@pytest.mark.parametrize(
Expand Down Expand Up @@ -345,7 +345,7 @@ def test_request_body_data(test_name, slicer_body_data, paginator_body_data, exp

if expected_body_data:
actual_body_data = retriever._request_body_data(None, None, None)
assert expected_body_data == actual_body_data
assert actual_body_data == expected_body_data
else:
try:
retriever._request_body_data(None, None, None)
Expand Down Expand Up @@ -380,7 +380,7 @@ def test_path(test_name, requester_path, paginator_path, expected_path):
)

actual_path = retriever._paginator_path()
assert expected_path == actual_path
assert actual_path == expected_path


def test_limit_stream_slices():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ def test_request_option(
)
stream_slice = {"owner_resource": "customer", "repository": "airbyte"}

assert expected_req_params == slicer.get_request_params(stream_slice=stream_slice)
assert expected_headers == slicer.get_request_headers(stream_slice=stream_slice)
assert expected_body_json == slicer.get_request_body_json(stream_slice=stream_slice)
assert expected_body_data == slicer.get_request_body_data(stream_slice=stream_slice)
assert slicer.get_request_params(stream_slice=stream_slice) == expected_req_params
assert slicer.get_request_headers(stream_slice=stream_slice) == expected_headers
assert slicer.get_request_body_json(stream_slice=stream_slice) == expected_body_json
assert slicer.get_request_body_data(stream_slice=stream_slice) == expected_body_data


def test_request_option_before_updating_cursor():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def test_read_manifest_declarative_source(test_name, manifest, pages, expected_r
_stream_name = "Rates"
with patch.object(SimpleRetriever, "_fetch_next_page", side_effect=pages) as mock_retriever:
output_data = [message.record.data for message in _run_read(manifest, _stream_name) if message.record]
assert expected_records == output_data
assert output_data == expected_records
mock_retriever.assert_has_calls(expected_calls)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_get_error_display_message_no_display_message(self):

display_message = facade.get_error_display_message(e)

assert expected_display_message == display_message
assert display_message == expected_display_message

def test_get_error_display_message_with_display_message(self):
self._stream.get_error_display_message.return_value = "display_message"
Expand All @@ -341,7 +341,7 @@ def test_get_error_display_message_with_display_message(self):

display_message = facade.get_error_display_message(e)

assert expected_display_message == display_message
assert display_message == expected_display_message


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def test_add_file(files_to_add: List[RemoteFile], expected_start_time: List[date

for index, f in enumerate(files_to_add):
cursor.add_file(f)
assert expected_start_time[index] == cursor._compute_start_time()
assert expected_state_dict == cursor.get_state()
assert cursor._compute_start_time() == expected_start_time[index]
assert cursor.get_state() == expected_state_dict


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _verify_state_record_counts(records: List[AirbyteMessage], states: List[Airb
)

for stream, actual_count in actual_record_counts.items():
assert state_record_count_sums.get(stream) == actual_count
assert actual_count == state_record_count_sums.get(stream)

# We can have extra keys in state_record_count_sums if we processed a stream and reported 0 records
extra_keys = state_record_count_sums.keys() - actual_record_counts.keys()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_get_error_display_message_no_display_message(self):

display_message = facade.get_error_display_message(e)

assert expected_display_message == display_message
assert display_message == expected_display_message

def test_get_error_display_message_with_display_message(self):
self._stream.get_error_display_message.return_value = "display_message"
Expand All @@ -359,7 +359,7 @@ def test_get_error_display_message_with_display_message(self):

display_message = facade.get_error_display_message(e)

assert expected_display_message == display_message
assert display_message == expected_display_message


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_handle_partition_done_no_other_streams_to_generate_partitions_for(self)
messages = list(handler.on_partition_generation_completed(sentinel))

expected_messages = []
assert expected_messages == messages
assert messages == expected_messages

@freezegun.freeze_time("2020-01-01T00:00:00")
def test_handle_last_stream_partition_done(self):
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_handle_last_stream_partition_done(self):
),
),
]
assert expected_messages == messages
assert messages == expected_messages
assert in_order_validation_mock.mock_calls.index(
call._another_stream.cursor.ensure_at_least_one_state_emitted
) < in_order_validation_mock.mock_calls.index(call._message_repository.consume_queue)
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_handle_on_partition_complete_sentinel_with_messages_from_repository(sel
expected_messages = [
AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=LogLevel.INFO, message="message emitted from the repository"))
]
assert expected_messages == messages
assert messages == expected_messages

partition.close.assert_called_once()

Expand Down Expand Up @@ -267,7 +267,7 @@ def test_handle_on_partition_complete_sentinel_yields_status_message_if_the_stre
),
)
]
assert expected_messages == messages
assert messages == expected_messages
self._a_closed_partition.close.assert_called_once()

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

expected_messages = []
assert expected_messages == messages
assert messages == expected_messages
partition.close.assert_called_once()

@freezegun.freeze_time("2020-01-01T00:00:00")
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_on_record_no_status_message_no_repository_messge(self):
),
)
]
assert expected_messages == messages
assert messages == expected_messages

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

@freezegun.freeze_time("2020-01-01T00:00:00")
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_on_record_emits_status_message_on_first_record_no_repository_message(se
),
),
]
assert expected_messages == messages
assert messages == expected_messages

@freezegun.freeze_time("2020-01-01T00:00:00")
def test_on_record_emits_status_message_on_first_record_with_repository_message(self):
Expand Down Expand Up @@ -477,7 +477,7 @@ def test_on_record_emits_status_message_on_first_record_with_repository_message(
),
AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=LogLevel.INFO, message="message emitted from the repository")),
]
assert expected_messages == messages
assert messages == expected_messages

@freezegun.freeze_time("2020-01-01T00:00:00")
def test_on_exception_return_trace_message_and_on_stream_complete_return_stream_status(self):
Expand Down
Loading

0 comments on commit b7819d9

Please sign in to comment.