Skip to content

Commit

Permalink
Add local file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Chia committed Jun 22, 2023
1 parent 0774115 commit 73f7a1a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/remote_io/test_url_download_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

import pathlib

import pytest

import daft
from tests.remote_io.conftest import YieldFixture


@pytest.fixture(scope="function")
def local_image_data_fixture(tmpdir, image_data) -> YieldFixture[list[str]]:
"""Populates the local tmpdir with some fake data and returns filepaths"""
# Dump some images into the tmpdir
tmpdir = pathlib.Path(tmpdir)
urls = []
for i in range(10):
path = tmpdir / f"{i}.jpeg"
path.write_bytes(image_data)
urls.append(str(path))

yield urls

# Cleanup tmpdir
for child in tmpdir.glob("*"):
child.unlink()


def test_url_download_local(local_image_data_fixture, image_data):
data = {"urls": local_image_data_fixture}
df = daft.from_pydict(data)
df = df.with_column("data", df["urls"].url.download())
assert df.to_pydict() == {**data, "data": [image_data for _ in range(len(local_image_data_fixture))]}

0 comments on commit 73f7a1a

Please sign in to comment.