Skip to content

Commit 8e54720

Browse files
committed
file-mode-api: ruff format .
1 parent 5df84a3 commit 8e54720

File tree

3 files changed

+82
-24
lines changed

3 files changed

+82
-24
lines changed

airbyte_cdk/sources/declarative/concurrent_declarative_source.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ def discover(self, logger: logging.Logger, config: Mapping[str, Any]) -> Airbyte
180180
]
181181
)
182182

183-
def streams(self, config: Mapping[str, Any], catalog: ConfiguredAirbyteCatalog | None = None) -> List[Stream]:
183+
def streams(
184+
self, config: Mapping[str, Any], catalog: ConfiguredAirbyteCatalog | None = None
185+
) -> List[Stream]:
184186
"""
185187
The `streams` method is used as part of the AbstractSource in the following cases:
186188
* ConcurrentDeclarativeSource.check -> ManifestDeclarativeSource.check -> AbstractSource.check -> DeclarativeSource.check_connection -> CheckStream.check_connection -> streams

airbyte_cdk/sources/declarative/manifest_declarative_source.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def connection_checker(self) -> ConnectionChecker:
142142
f"Expected to generate a ConnectionChecker component, but received {check_stream.__class__}"
143143
)
144144

145-
def streams(self, config: Mapping[str, Any], catalog: Optional[ConfiguredAirbyteCatalog] = None) -> List[Stream]:
145+
def streams(
146+
self, config: Mapping[str, Any], catalog: Optional[ConfiguredAirbyteCatalog] = None
147+
) -> List[Stream]:
146148
self._emit_manifest_debug_message(
147149
extra_args={"source_name": self.name, "parsed_config": json.dumps(self._source_config)}
148150
)
@@ -164,7 +166,9 @@ def streams(self, config: Mapping[str, Any], catalog: Optional[ConfiguredAirbyte
164166
stream_config,
165167
config,
166168
emit_connector_builder_messages=self._emit_connector_builder_messages,
167-
include_files=self._get_include_files(stream_config=stream_config, catalog_with_streams_name=catalog_with_streams_name),
169+
include_files=self._get_include_files(
170+
stream_config=stream_config, catalog_with_streams_name=catalog_with_streams_name
171+
),
168172
)
169173
for stream_config in self._initialize_cache_for_parent_streams(deepcopy(stream_configs))
170174
]
@@ -173,7 +177,8 @@ def streams(self, config: Mapping[str, Any], catalog: Optional[ConfiguredAirbyte
173177

174178
@staticmethod
175179
def _get_include_files(
176-
stream_config: Dict[str, Any], catalog_with_streams_name: Mapping[str, ConfiguredAirbyteStream] | None
180+
stream_config: Dict[str, Any],
181+
catalog_with_streams_name: Mapping[str, ConfiguredAirbyteStream] | None,
177182
) -> Optional[bool]:
178183
"""
179184
Returns the include_files for the stream if it exists in the catalog.
@@ -185,12 +190,17 @@ def _get_include_files(
185190
return False
186191

187192
@staticmethod
188-
def _catalog_with_streams_name(catalog: ConfiguredAirbyteCatalog | None) -> Mapping[str, ConfiguredAirbyteStream] | None:
193+
def _catalog_with_streams_name(
194+
catalog: ConfiguredAirbyteCatalog | None,
195+
) -> Mapping[str, ConfiguredAirbyteStream] | None:
189196
"""
190197
Returns a dict mapping stream names to their corresponding ConfiguredAirbyteStream objects.
191198
"""
192199
if catalog:
193-
return { configured_stream.stream.name: configured_stream for configured_stream in catalog.streams}
200+
return {
201+
configured_stream.stream.name: configured_stream
202+
for configured_stream in catalog.streams
203+
}
194204
return None
195205

196206
@staticmethod

unit_tests/sources/declarative/file/test_file_stream.py

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ def test_get_articles(self) -> None:
120120
assert output.records
121121

122122
def test_get_article_attachments(self) -> None:
123-
with HttpMocker() as http_mocker, patch(
124-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write') as mock_noop_write, patch(
125-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write') as mock_file_system_write:
123+
with (
124+
HttpMocker() as http_mocker,
125+
patch(
126+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write"
127+
) as mock_noop_write,
128+
patch(
129+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write"
130+
) as mock_file_system_write,
131+
):
126132
http_mocker.get(
127133
HttpRequest(url=STREAM_URL),
128134
HttpResponse(json.dumps(find_template("file_api/articles", __file__)), 200),
@@ -146,7 +152,11 @@ def test_get_article_attachments(self) -> None:
146152
output = read(
147153
self._config(),
148154
CatalogBuilder()
149-
.with_stream(ConfiguredAirbyteStreamBuilder().with_name("article_attachments").with_include_files(True))
155+
.with_stream(
156+
ConfiguredAirbyteStreamBuilder()
157+
.with_name("article_attachments")
158+
.with_include_files(True)
159+
)
150160
.build(),
151161
)
152162

@@ -190,19 +200,31 @@ def test_get_article_attachments_and_file_is_uploaded(self) -> None:
190200
output = read(
191201
self._config(),
192202
CatalogBuilder()
193-
.with_stream(ConfiguredAirbyteStreamBuilder().with_name("article_attachments").with_include_files(True))
203+
.with_stream(
204+
ConfiguredAirbyteStreamBuilder()
205+
.with_name("article_attachments")
206+
.with_include_files(True)
207+
)
194208
.build(),
195209
yaml_file="test_file_stream_with_filename_extractor.yaml",
196210
)
197211
file_reference = output.records[0].record.file_reference
198212
assert file_reference.file_size_bytes
199-
assert Path(file_reference.staging_file_url).exists(), "File should be uploaded to the staging directory"
213+
assert Path(file_reference.staging_file_url).exists(), (
214+
"File should be uploaded to the staging directory"
215+
)
200216

201217
def test_get_article_attachments_with_filename_extractor(self) -> None:
202218
"""Test that article attachments can be read with filename extractor and file system writer is called"""
203-
with HttpMocker() as http_mocker, patch(
204-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write') as mock_noop_write, patch(
205-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write') as mock_file_system_write:
219+
with (
220+
HttpMocker() as http_mocker,
221+
patch(
222+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write"
223+
) as mock_noop_write,
224+
patch(
225+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write"
226+
) as mock_file_system_write,
227+
):
206228
http_mocker.get(
207229
HttpRequest(url=STREAM_URL),
208230
HttpResponse(json.dumps(find_template("file_api/articles", __file__)), 200),
@@ -226,7 +248,11 @@ def test_get_article_attachments_with_filename_extractor(self) -> None:
226248
output = read(
227249
self._config(),
228250
CatalogBuilder()
229-
.with_stream(ConfiguredAirbyteStreamBuilder().with_name("article_attachments").with_include_files(True))
251+
.with_stream(
252+
ConfiguredAirbyteStreamBuilder()
253+
.with_name("article_attachments")
254+
.with_include_files(True)
255+
)
230256
.build(),
231257
yaml_file="test_file_stream_with_filename_extractor.yaml",
232258
)
@@ -251,9 +277,15 @@ def test_get_article_attachments_with_filename_extractor(self) -> None:
251277
def test_get_article_attachments_without_include_files(self) -> None:
252278
"""Test that article attachments can be read without including files, it can be opt-out by configured catalog"""
253279
include_files = False
254-
with HttpMocker() as http_mocker, patch(
255-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write') as mock_noop_write, patch(
256-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write') as mock_file_system_write:
280+
with (
281+
HttpMocker() as http_mocker,
282+
patch(
283+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write"
284+
) as mock_noop_write,
285+
patch(
286+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write"
287+
) as mock_file_system_write,
288+
):
257289
http_mocker.get(
258290
HttpRequest(url=STREAM_URL),
259291
HttpResponse(json.dumps(find_template("file_api/articles", __file__)), 200),
@@ -276,7 +308,11 @@ def test_get_article_attachments_without_include_files(self) -> None:
276308
output = read(
277309
self._config(),
278310
CatalogBuilder()
279-
.with_stream(ConfiguredAirbyteStreamBuilder().with_name("article_attachments").with_include_files(include_files))
311+
.with_stream(
312+
ConfiguredAirbyteStreamBuilder()
313+
.with_name("article_attachments")
314+
.with_include_files(include_files)
315+
)
280316
.build(),
281317
yaml_file="test_file_stream_with_filename_extractor.yaml",
282318
)
@@ -300,9 +336,15 @@ def test_get_article_attachments_without_include_files(self) -> None:
300336
assert file_reference.file_size_bytes == NoopFileWriter.NOOP_FILE_SIZE
301337

302338
def test_get_article_attachments_messages_for_connector_builder(self) -> None:
303-
with HttpMocker() as http_mocker, patch(
304-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write') as mock_noop_write, patch(
305-
'airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write') as mock_file_system_write:
339+
with (
340+
HttpMocker() as http_mocker,
341+
patch(
342+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write"
343+
) as mock_noop_write,
344+
patch(
345+
"airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write"
346+
) as mock_file_system_write,
347+
):
306348
http_mocker.get(
307349
HttpRequest(url=STREAM_URL),
308350
HttpResponse(json.dumps(find_template("file_api/articles", __file__)), 200),
@@ -337,7 +379,11 @@ def __init__(self, *args, **kwargs):
337379
output = read(
338380
self._config(),
339381
CatalogBuilder()
340-
.with_stream(ConfiguredAirbyteStreamBuilder().with_name("article_attachments").with_include_files(True))
382+
.with_stream(
383+
ConfiguredAirbyteStreamBuilder()
384+
.with_name("article_attachments")
385+
.with_include_files(True)
386+
)
341387
.build(),
342388
yaml_file="test_file_stream_with_filename_extractor.yaml",
343389
)

0 commit comments

Comments
 (0)