Skip to content

Commit

Permalink
test: searching a directory with multiple nested directories should w…
Browse files Browse the repository at this point in the history
…ork (#129)

Related to #8.
  • Loading branch information
yurijmikhalevich authored Jun 23, 2024
1 parent f568c18 commit a80cb44
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 3 deletions.
Binary file added tests/e2e/images nested directories/cake.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/images nested directories/cats/cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
score filepath
0.299 "<test_images_dir>misc/bees/bee.jpg"
0.246 "<test_images_dir>misc/tree.webp"
0.213 "<test_images_dir>cake.jpg"
0.212 "<test_images_dir>chessboard with rocks.JPG"
0.211 "<test_images_dir>cats/cat.jpg"
0.203 "<test_images_dir>cats/black cat sleeping on a chair.JPG"
0.195 "<test_images_dir>cats/black cat at night.jpg"
0.194 "<test_images_dir>cameras/camera.jpg"
0.192 "<test_images_dir>cameras/camera lens.jpg"
0.187 "<test_images_dir>cats/black kitty.jpeg"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
score filepath
0.261 "<test_images_dir>cats/black cat at night.jpg"
0.251 "<test_images_dir>cats/black cat sleeping on a chair.JPG"
0.248 "<test_images_dir>cats/cat.jpg"
0.247 "<test_images_dir>cats/black kitty.jpeg"
0.244 "<test_images_dir>cats/cautious cat.jpg"
0.184 "<test_images_dir>misc/tree.webp"
0.178 "<test_images_dir>cameras/camera.jpg"
0.175 "<test_images_dir>cake.jpg"
0.171 "<test_images_dir>chessboard with rocks.JPG"
0.164 "<test_images_dir>misc/boats on a lake.png"
42 changes: 39 additions & 3 deletions tests/e2e/test_rclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,35 @@ def test_empty_dir():


@pytest.fixture
def assert_output_snapshot(test_images_dir: Path, request: pytest.FixtureRequest, capsys: pytest.CaptureFixture[str]):
yield
def test_dir_with_nested_directories():
return Path(__file__).parent / 'images nested directories'


def _assert_output_snapshot(images_dir: Path, request: pytest.FixtureRequest, capsys: pytest.CaptureFixture[str]):
out, _ = capsys.readouterr()
snapshot_path = Path(__file__).parent / 'output_snapshots' / f'{request.node.name}.txt'
snapshot = out.replace(str(test_images_dir) + os.path.sep, '<test_images_dir>')
snapshot = out.replace(str(images_dir) + os.path.sep, '<test_images_dir>').replace(os.path.sep, '/')
if not snapshot_path.exists():
snapshot_path.write_text(snapshot)
assert snapshot == snapshot_path.read_text()


@pytest.fixture
def assert_output_snapshot(test_images_dir: Path, request: pytest.FixtureRequest, capsys: pytest.CaptureFixture[str]):
yield
_assert_output_snapshot(test_images_dir, request, capsys)


@pytest.fixture
def assert_output_snapshot_nested_directories(
test_dir_with_nested_directories: Path,
request: pytest.FixtureRequest,
capsys: pytest.CaptureFixture[str],
):
yield
_assert_output_snapshot(test_dir_with_nested_directories, request, capsys)


def execute_query(test_images_dir: Path, monkeypatch: pytest.MonkeyPatch, *args: str):
with tempfile.TemporaryDirectory() as tmpdirname:
monkeypatch.setenv('RCLIP_DATADIR', tmpdirname)
Expand Down Expand Up @@ -127,3 +146,20 @@ def test_combine_image_query_with_text_query(test_images_dir: Path, monkeypatch:
@pytest.mark.usefixtures('assert_output_snapshot')
def test_seach_empty_dir(test_empty_dir: Path, monkeypatch: pytest.MonkeyPatch):
execute_query(test_empty_dir, monkeypatch, 'kitty')


@pytest.mark.usefixtures('assert_output_snapshot_nested_directories')
def test_seach_dir_with_multiple_nested_directories(
test_dir_with_nested_directories: Path,
monkeypatch: pytest.MonkeyPatch,
):
execute_query(test_dir_with_nested_directories, monkeypatch, 'kitty')


@pytest.mark.usefixtures('assert_output_snapshot_nested_directories')
def test_seach_dir_with_deeply_nested_directories(
test_dir_with_nested_directories: Path,
monkeypatch: pytest.MonkeyPatch,
):
# output should contain a nested path to the bee image
execute_query(test_dir_with_nested_directories, monkeypatch, 'bee')

0 comments on commit a80cb44

Please sign in to comment.