Skip to content

Commit 7a750d6

Browse files
authored
Merge branch 'devin/1744436819-cherry-pick-test-fixes' into aj/feat/mini-cat-test-suites
2 parents e4cae20 + eb0f643 commit 7a750d6

File tree

11 files changed

+49
-120
lines changed

11 files changed

+49
-120
lines changed

airbyte_cdk/connector_builder/connector_builder_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
from dataclasses import asdict, dataclass, field
7-
from typing import Any, Dict, List, Mapping
7+
from typing import Any, ClassVar, Dict, List, Mapping
88

99
from airbyte_cdk.connector_builder.test_reader import TestReader
1010
from airbyte_cdk.models import (
@@ -35,9 +35,9 @@
3535
MAX_STREAMS_KEY = "max_streams"
3636

3737

38-
@dataclass(kw_only=True)
38+
@dataclass
3939
class TestLimits:
40-
__test__: bool = False # Prevent pytest from treating this as a test case, despite its name
40+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
4141

4242
max_records: int = field(default=DEFAULT_MAXIMUM_RECORDS)
4343
max_pages_per_slice: int = field(default=DEFAULT_MAXIMUM_NUMBER_OF_PAGES_PER_SLICE)

airbyte_cdk/connector_builder/test_reader/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
import logging
7-
from typing import Any, Dict, Iterator, List, Mapping, Optional, Union
7+
from typing import Any, ClassVar, Dict, Iterator, List, Mapping, Optional, Union
88

99
from airbyte_cdk.connector_builder.models import (
1010
AuxiliaryRequest,
@@ -66,7 +66,7 @@ class TestReader:
6666
6767
"""
6868

69-
__test__: bool = False # Prevent pytest from treating this as a test case, despite its name
69+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
7070

7171
logger = logging.getLogger("airbyte.connector-builder")
7272

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ filterwarnings =
88
markers =
99
slow: mark tests as slow
1010
asyncio: mark test as asyncio
11+
requires_creds: mark test as requiring credentials

unit_tests/connector_builder/test_connector_builder_handler.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,7 @@ def test_create_source() -> None:
983983
max_records = 3
984984
max_pages_per_slice = 2
985985
max_slices = 1
986-
limits = TestLimits(
987-
max_records=max_records,
988-
max_pages_per_slice=max_pages_per_slice,
989-
max_slices=max_slices,
990-
)
986+
limits = TestLimits(max_records, max_pages_per_slice, max_slices)
991987

992988
config = {"__injected_declarative_manifest": MANIFEST}
993989

@@ -1069,11 +1065,7 @@ def test_read_source(mock_http_stream):
10691065
max_records = 100
10701066
max_pages_per_slice = 2
10711067
max_slices = 3
1072-
limits = TestLimits(
1073-
max_records=max_records,
1074-
max_pages_per_slice=max_pages_per_slice,
1075-
max_slices=max_slices,
1076-
)
1068+
limits = TestLimits(max_records, max_pages_per_slice, max_slices)
10771069

10781070
catalog = ConfiguredAirbyteCatalog(
10791071
streams=[
@@ -1120,11 +1112,7 @@ def test_read_source_single_page_single_slice(mock_http_stream):
11201112
max_records = 100
11211113
max_pages_per_slice = 1
11221114
max_slices = 1
1123-
limits = TestLimits(
1124-
max_records=max_records,
1125-
max_pages_per_slice=max_pages_per_slice,
1126-
max_slices=max_slices,
1127-
)
1115+
limits = TestLimits(max_records, max_pages_per_slice, max_slices)
11281116

11291117
catalog = ConfiguredAirbyteCatalog(
11301118
streams=[
@@ -1208,11 +1196,7 @@ def test_handle_read_external_requests(deployment_mode, url_base, expected_error
12081196
endpoints when running on Cloud or OSS deployments
12091197
"""
12101198

1211-
limits = TestLimits(
1212-
max_records=100,
1213-
max_pages_per_slice=1,
1214-
max_slices=1,
1215-
)
1199+
limits = TestLimits(max_records=100, max_pages_per_slice=1, max_slices=1)
12161200

12171201
catalog = ConfiguredAirbyteCatalog(
12181202
streams=[
@@ -1298,11 +1282,7 @@ def test_handle_read_external_oauth_request(deployment_mode, token_url, expected
12981282
endpoints when running on Cloud or OSS deployments
12991283
"""
13001284

1301-
limits = TestLimits(
1302-
max_records=100,
1303-
max_pages_per_slice=1,
1304-
max_slices=1,
1305-
)
1285+
limits = TestLimits(max_records=100, max_pages_per_slice=1, max_slices=1)
13061286

13071287
catalog = ConfiguredAirbyteCatalog(
13081288
streams=[

unit_tests/connector_builder/test_message_grouper.py

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ def test_get_grouped_messages(mock_entrypoint_read: Mock) -> None:
203203
),
204204
)
205205

206-
connector_builder_handler = TestReader(
207-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
208-
max_slices=MAX_SLICES,
209-
)
206+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
210207
actual_response: StreamRead = connector_builder_handler.run_test_read(
211208
source=mock_source,
212209
config=CONFIG,
@@ -290,10 +287,7 @@ def test_get_grouped_messages_with_logs(mock_entrypoint_read: Mock) -> None:
290287
),
291288
)
292289

293-
connector_builder_handler = TestReader(
294-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
295-
max_slices=MAX_SLICES,
296-
)
290+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
297291

298292
actual_response: StreamRead = connector_builder_handler.run_test_read(
299293
source=mock_source,
@@ -346,11 +340,7 @@ def test_get_grouped_messages_record_limit(
346340
n_records = 2
347341
record_limit = min(request_record_limit, max_record_limit)
348342

349-
api = TestReader(
350-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
351-
max_slices=MAX_SLICES,
352-
max_record_limit=max_record_limit,
353-
)
343+
api = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES, max_record_limit=max_record_limit)
354344
# this is the call we expect to raise an exception
355345
if should_fail:
356346
with pytest.raises(ValueError):
@@ -414,11 +404,7 @@ def test_get_grouped_messages_default_record_limit(
414404
)
415405
n_records = 2
416406

417-
api = TestReader(
418-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
419-
max_slices=MAX_SLICES,
420-
max_record_limit=max_record_limit,
421-
)
407+
api = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES, max_record_limit=max_record_limit)
422408
actual_response: StreamRead = api.run_test_read(
423409
source=mock_source,
424410
config=CONFIG,
@@ -457,10 +443,7 @@ def test_get_grouped_messages_limit_0(mock_entrypoint_read: Mock) -> None:
457443
]
458444
),
459445
)
460-
api = TestReader(
461-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
462-
max_slices=MAX_SLICES,
463-
)
446+
api = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
464447

465448
with pytest.raises(ValueError):
466449
api.run_test_read(
@@ -518,10 +501,7 @@ def test_get_grouped_messages_no_records(mock_entrypoint_read: Mock) -> None:
518501
),
519502
)
520503

521-
message_grouper = TestReader(
522-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
523-
max_slices=MAX_SLICES,
524-
)
504+
message_grouper = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
525505

526506
actual_response: StreamRead = message_grouper.run_test_read(
527507
source=mock_source,
@@ -634,10 +614,7 @@ def test_get_grouped_messages_with_many_slices(mock_entrypoint_read: Mock) -> No
634614
),
635615
)
636616

637-
connector_builder_handler = TestReader(
638-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
639-
max_slices=MAX_SLICES,
640-
)
617+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
641618

642619
stream_read: StreamRead = connector_builder_handler.run_test_read(
643620
source=mock_source,
@@ -681,10 +658,7 @@ def test_get_grouped_messages_given_maximum_number_of_slices_then_test_read_limi
681658
),
682659
)
683660

684-
api = TestReader(
685-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
686-
max_slices=MAX_SLICES,
687-
)
661+
api = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
688662

689663
stream_read: StreamRead = api.run_test_read(
690664
source=mock_source,
@@ -712,10 +686,7 @@ def test_get_grouped_messages_given_maximum_number_of_pages_then_test_read_limit
712686
),
713687
)
714688

715-
api = TestReader(
716-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
717-
max_slices=MAX_SLICES,
718-
)
689+
api = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
719690

720691
stream_read: StreamRead = api.run_test_read(
721692
source=mock_source,
@@ -734,10 +705,7 @@ def test_read_stream_returns_error_if_stream_does_not_exist() -> None:
734705

735706
full_config: Mapping[str, Any] = {**CONFIG, **{"__injected_declarative_manifest": MANIFEST}}
736707

737-
message_grouper = TestReader(
738-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
739-
max_slices=MAX_SLICES,
740-
)
708+
message_grouper = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
741709
actual_response = message_grouper.run_test_read(
742710
source=mock_source,
743711
config=full_config,
@@ -762,10 +730,7 @@ def test_given_control_message_then_stream_read_has_config_update(
762730
+ [connector_configuration_control_message(1, updated_config)]
763731
),
764732
)
765-
connector_builder_handler = TestReader(
766-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
767-
max_slices=MAX_SLICES,
768-
)
733+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
769734
stream_read: StreamRead = connector_builder_handler.run_test_read(
770735
source=mock_source,
771736
config=CONFIG,
@@ -795,10 +760,7 @@ def test_given_multiple_control_messages_then_stream_read_has_latest_based_on_em
795760
]
796761
),
797762
)
798-
connector_builder_handler = TestReader(
799-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
800-
max_slices=MAX_SLICES,
801-
)
763+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
802764
stream_read: StreamRead = connector_builder_handler.run_test_read(
803765
source=mock_source,
804766
config=CONFIG,
@@ -826,10 +788,7 @@ def test_given_multiple_control_messages_with_same_timestamp_then_stream_read_ha
826788
]
827789
),
828790
)
829-
connector_builder_handler = TestReader(
830-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
831-
max_slices=MAX_SLICES,
832-
)
791+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
833792
stream_read: StreamRead = connector_builder_handler.run_test_read(
834793
source=mock_source,
835794
config=CONFIG,
@@ -846,10 +805,7 @@ def test_given_auxiliary_requests_then_return_auxiliary_request(mock_entrypoint_
846805
mock_entrypoint_read,
847806
iter(any_request_and_response_with_a_record() + [auxiliary_request_log_message()]),
848807
)
849-
connector_builder_handler = TestReader(
850-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
851-
max_slices=MAX_SLICES,
852-
)
808+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
853809
stream_read: StreamRead = connector_builder_handler.run_test_read(
854810
source=mock_source,
855811
config=CONFIG,
@@ -863,10 +819,7 @@ def test_given_auxiliary_requests_then_return_auxiliary_request(mock_entrypoint_
863819
@patch("airbyte_cdk.connector_builder.test_reader.reader.AirbyteEntrypoint.read")
864820
def test_given_no_slices_then_return_empty_slices(mock_entrypoint_read: Mock) -> None:
865821
mock_source = make_mock_source(mock_entrypoint_read, iter([auxiliary_request_log_message()]))
866-
connector_builder_handler = TestReader(
867-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
868-
max_slices=MAX_SLICES,
869-
)
822+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
870823
stream_read: StreamRead = connector_builder_handler.run_test_read(
871824
source=mock_source,
872825
config=CONFIG,
@@ -892,10 +845,7 @@ def test_given_pk_then_ensure_pk_is_pass_to_schema_inferrence(mock_entrypoint_re
892845
mock_source.streams.return_value = [Mock()]
893846
mock_source.streams.return_value[0].primary_key = [["id"]]
894847
mock_source.streams.return_value[0].cursor_field = _NO_CURSOR_FIELD
895-
connector_builder_handler = TestReader(
896-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
897-
max_slices=MAX_SLICES,
898-
)
848+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
899849

900850
stream_read: StreamRead = connector_builder_handler.run_test_read(
901851
source=mock_source,
@@ -924,10 +874,7 @@ def test_given_cursor_field_then_ensure_cursor_field_is_pass_to_schema_inferrenc
924874
mock_source.streams.return_value = [Mock()]
925875
mock_source.streams.return_value[0].primary_key = _NO_PK
926876
mock_source.streams.return_value[0].cursor_field = ["date"]
927-
connector_builder_handler = TestReader(
928-
max_pages_per_slice=MAX_PAGES_PER_SLICE,
929-
max_slices=MAX_SLICES,
930-
)
877+
connector_builder_handler = TestReader(MAX_PAGES_PER_SLICE, MAX_SLICES)
931878

932879
stream_read: StreamRead = connector_builder_handler.run_test_read(
933880
source=mock_source,

unit_tests/sources/declarative/decoders/test_composite_decoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from http.server import BaseHTTPRequestHandler, HTTPServer
99
from io import BytesIO, StringIO
1010
from threading import Thread
11-
from typing import Iterable
11+
from typing import ClassVar, Iterable
1212
from unittest.mock import Mock, patch
1313

1414
import pytest
@@ -259,7 +259,7 @@ def test_composite_raw_decoder_csv_parser_values(requests_mock, encoding: str, d
259259

260260

261261
class TestServer(BaseHTTPRequestHandler):
262-
__test__ = False # Prevent pytest from thinking that this is a test class, despite the name
262+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
263263

264264
def do_GET(self) -> None:
265265
self.send_response(200)

unit_tests/sources/declarative/parsers/testing_components.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
from dataclasses import dataclass, field
6-
from typing import List, Optional
6+
from typing import ClassVar, List, Optional
77

88
from airbyte_cdk.sources.declarative.extractors import DpathExtractor
99
from airbyte_cdk.sources.declarative.partition_routers import SubstreamPartitionRouter
@@ -15,13 +15,13 @@
1515
)
1616

1717

18-
@dataclass(kw_only=True)
18+
@dataclass
1919
class TestingSomeComponent(DefaultErrorHandler):
2020
"""
2121
A basic test class with various field permutations used to test manifests with custom components
2222
"""
2323

24-
__test__ = False # Prevent pytest from thinking that this is a test class, despite the name
24+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
2525

2626
subcomponent_field_with_hint: DpathExtractor = field(
2727
default_factory=lambda: DpathExtractor(field_path=[], config={}, parameters={})
@@ -33,13 +33,13 @@ class TestingSomeComponent(DefaultErrorHandler):
3333
paginator: DefaultPaginator = None
3434

3535

36-
@dataclass(kw_only=True)
36+
@dataclass
3737
class TestingCustomSubstreamPartitionRouter(SubstreamPartitionRouter):
3838
"""
3939
A test class based on a SubstreamPartitionRouter used for testing manifests that use custom components.
4040
"""
4141

42-
__test__ = False # Prevent pytest from thinking that this is a test class, despite the name
42+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
4343

4444
custom_field: str
4545
custom_pagination_strategy: PaginationStrategy

0 commit comments

Comments
 (0)