Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Apr 2, 2024
1 parent 1b34211 commit ff03e9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
22 changes: 6 additions & 16 deletions tests/load/filesystem/test_filesystem_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from dlt.common.utils import digest128, uniq_id
from dlt.common.storages import FileStorage, ParsedLoadJobFileName

from dlt.destinations.impl.filesystem.filesystem import (
LoadFilesystemJob,
FilesystemDestinationClientConfiguration,
)
from dlt.destinations.impl.filesystem.filesystem import FilesystemDestinationClientConfiguration
from dlt.destinations.impl.filesystem.layout import make_filename

from tests.load.filesystem.utils import perform_load
from tests.utils import clean_test_storage, init_test_logging
Expand Down Expand Up @@ -102,9 +100,7 @@ def test_replace_write_disposition(layout: str, default_buckets_env: str) -> Non
# this path will be kept after replace
job_2_load_1_path = posixpath.join(
root_path,
LoadFilesystemJob.make_destination_filename(
layout, NORMALIZED_FILES[1], client.schema.name, load_id1
),
make_filename(client.config, NORMALIZED_FILES[1], client.schema.name, load_id1),
)

with perform_load(
Expand All @@ -115,9 +111,7 @@ def test_replace_write_disposition(layout: str, default_buckets_env: str) -> Non
# this one we expect to be replaced with
job_1_load_2_path = posixpath.join(
root_path,
LoadFilesystemJob.make_destination_filename(
layout, NORMALIZED_FILES[0], client.schema.name, load_id2
),
make_filename(client.config, NORMALIZED_FILES[0], client.schema.name, load_id2),
)

# First file from load1 remains, second file is replaced by load2
Expand Down Expand Up @@ -147,14 +141,10 @@ def test_append_write_disposition(layout: str, default_buckets_env: str) -> None
client, jobs2, root_path, load_id2 = load_info
layout = client.config.layout
expected_files = [
LoadFilesystemJob.make_destination_filename(
layout, job.file_name(), client.schema.name, load_id1
)
make_filename(client.config, job.file_name(), client.schema.name, load_id1)
for job in jobs1
] + [
LoadFilesystemJob.make_destination_filename(
layout, job.file_name(), client.schema.name, load_id2
)
make_filename(client.config, job.file_name(), client.schema.name, load_id2)
for job in jobs2
]
expected_files = sorted([posixpath.join(root_path, fn) for fn in expected_files])
Expand Down
14 changes: 8 additions & 6 deletions tests/load/pipeline/test_filesystem_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
import dlt, os
from dlt.common.utils import uniq_id
from dlt.common.storages.load_storage import LoadJobInfo
from dlt.destinations.impl.filesystem.filesystem import FilesystemClient, LoadFilesystemJob
from dlt.destinations.impl.filesystem.configuration import FilesystemDestinationClientConfiguration
from dlt.destinations.impl.filesystem.filesystem import FilesystemClient
from dlt.destinations.impl.filesystem.layout import make_filename
from dlt.common.schema.typing import LOADS_TABLE_NAME

from tests.utils import skip_if_not_active

skip_if_not_active("filesystem")


def assert_file_matches(
layout: str, job: LoadJobInfo, load_id: str, client: FilesystemClient
config: FilesystemDestinationClientConfiguration,
job: LoadJobInfo,
load_id: str,
client: FilesystemClient,
) -> None:
"""Verify file contents of load job are identical to the corresponding file in destination"""
local_path = Path(job.file_path)
filename = local_path.name

destination_fn = LoadFilesystemJob.make_destination_filename(
layout, filename, client.schema.name, load_id
)
destination_fn = make_filename(config.layout, filename, client.schema.name, load_id)
destination_path = posixpath.join(client.dataset_path, destination_fn)

assert local_path.read_bytes() == client.fs_client.read_bytes(destination_path)
Expand Down

0 comments on commit ff03e9e

Please sign in to comment.