Skip to content

Commit

Permalink
ci: enable tests on Windows (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurijmikhalevich authored Apr 14, 2024
1 parent 95a9774 commit 942c428
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
matrix:
python: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-22.04, macos-13]
os: [ubuntu-22.04, macos-13, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions rclip/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, filename: Union[str, pathlib.Path]):
self.ensure_tables()
self.ensure_version()

def close(self):
self._con.commit()
self._con.close()

def ensure_tables(self):
self._con.execute('''
CREATE TABLE IF NOT EXISTS images (
Expand Down
27 changes: 16 additions & 11 deletions rclip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,29 @@ def main():
if is_snap():
check_snap_permissions(current_directory)

rclip, _, _ = init_rclip(
rclip, _, db = init_rclip(
current_directory,
args.indexing_batch_size,
vars(args).get("device", "cpu"),
args.exclude_dir,
args.no_indexing,
)

result = rclip.search(args.query, current_directory, args.top, args.add, args.subtract)
if args.filepath_only:
for r in result:
print(r.filepath)
else:
print('score\tfilepath')
for r in result:
print(f'{r.score:.3f}\t"{r.filepath}"')
if args.preview:
preview(r.filepath, args.preview_height)
try:
result = rclip.search(args.query, current_directory, args.top, args.add, args.subtract)
if args.filepath_only:
for r in result:
print(r.filepath)
else:
print('score\tfilepath')
for r in result:
print(f'{r.score:.3f}\t"{r.filepath}"')
if args.preview:
preview(r.filepath, args.preview_height)
except Exception as e:
raise e
finally:
db.close()


if __name__ == '__main__':
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_add_and_subtract_queries.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.273 "<test_images_dir>/black cat at night.jpg"
0.263 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.245 "<test_images_dir>/cautious cat.jpg"
0.241 "<test_images_dir>/black kitty.jpg"
0.236 "<test_images_dir>/cat.jpg"
0.185 "<test_images_dir>/cake.jpg"
0.182 "<test_images_dir>/camera.jpg"
0.181 "<test_images_dir>/chessboard with rocks.JPG"
0.174 "<test_images_dir>/books.jpg"
0.165 "<test_images_dir>/camera lens.jpg"
0.273 "<test_images_dir>black cat at night.jpg"
0.263 "<test_images_dir>black cat sleeping on a chair.JPG"
0.245 "<test_images_dir>cautious cat.jpg"
0.241 "<test_images_dir>black kitty.jpg"
0.236 "<test_images_dir>cat.jpg"
0.185 "<test_images_dir>cake.jpg"
0.182 "<test_images_dir>camera.jpg"
0.181 "<test_images_dir>chessboard with rocks.JPG"
0.174 "<test_images_dir>books.jpg"
0.165 "<test_images_dir>camera lens.jpg"
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_add_queries.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.910 "<test_images_dir>/black cat at night.jpg"
0.881 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.877 "<test_images_dir>/cautious cat.jpg"
0.841 "<test_images_dir>/cat.jpg"
0.822 "<test_images_dir>/black kitty.jpg"
0.774 "<test_images_dir>/chessboard with rocks.JPG"
0.744 "<test_images_dir>/camera.jpg"
0.722 "<test_images_dir>/boats on a lake.jpg"
0.717 "<test_images_dir>/cake.jpg"
0.713 "<test_images_dir>/bee.jpg"
0.910 "<test_images_dir>black cat at night.jpg"
0.881 "<test_images_dir>black cat sleeping on a chair.JPG"
0.877 "<test_images_dir>cautious cat.jpg"
0.841 "<test_images_dir>cat.jpg"
0.822 "<test_images_dir>black kitty.jpg"
0.774 "<test_images_dir>chessboard with rocks.JPG"
0.744 "<test_images_dir>camera.jpg"
0.722 "<test_images_dir>boats on a lake.jpg"
0.717 "<test_images_dir>cake.jpg"
0.713 "<test_images_dir>bee.jpg"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.046 "<test_images_dir>/bee.jpg"
-0.045 "<test_images_dir>/camera lens.jpg"
-0.065 "<test_images_dir>/cake.jpg"
-0.088 "<test_images_dir>/camera.jpg"
-0.119 "<test_images_dir>/books.jpg"
-0.122 "<test_images_dir>/chessboard with rocks.JPG"
-0.123 "<test_images_dir>/boats on a lake.jpg"
-0.190 "<test_images_dir>/black cat at night.jpg"
-0.202 "<test_images_dir>/cautious cat.jpg"
-0.225 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.046 "<test_images_dir>bee.jpg"
-0.045 "<test_images_dir>camera lens.jpg"
-0.065 "<test_images_dir>cake.jpg"
-0.088 "<test_images_dir>camera.jpg"
-0.119 "<test_images_dir>books.jpg"
-0.122 "<test_images_dir>chessboard with rocks.JPG"
-0.123 "<test_images_dir>boats on a lake.jpg"
-0.190 "<test_images_dir>black cat at night.jpg"
-0.202 "<test_images_dir>cautious cat.jpg"
-0.225 "<test_images_dir>black cat sleeping on a chair.JPG"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.652 "<test_images_dir>/bee.jpg"
0.482 "<test_images_dir>/cake.jpg"
0.471 "<test_images_dir>/chessboard with rocks.JPG"
0.449 "<test_images_dir>/black kitty.jpg"
0.403 "<test_images_dir>/camera.jpg"
0.396 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.386 "<test_images_dir>/books.jpg"
0.379 "<test_images_dir>/boats on a lake.jpg"
0.367 "<test_images_dir>/black cat at night.jpg"
0.361 "<test_images_dir>/camera lens.jpg"
0.652 "<test_images_dir>bee.jpg"
0.482 "<test_images_dir>cake.jpg"
0.471 "<test_images_dir>chessboard with rocks.JPG"
0.449 "<test_images_dir>black kitty.jpg"
0.403 "<test_images_dir>camera.jpg"
0.396 "<test_images_dir>black cat sleeping on a chair.JPG"
0.386 "<test_images_dir>books.jpg"
0.379 "<test_images_dir>boats on a lake.jpg"
0.367 "<test_images_dir>black cat at night.jpg"
0.361 "<test_images_dir>camera lens.jpg"
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_query_multipliers.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.654 "<test_images_dir>/black cat at night.jpg"
0.595 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.582 "<test_images_dir>/cat.jpg"
0.579 "<test_images_dir>/black kitty.jpg"
0.535 "<test_images_dir>/cautious cat.jpg"
0.472 "<test_images_dir>/chessboard with rocks.JPG"
0.472 "<test_images_dir>/camera.jpg"
0.467 "<test_images_dir>/cake.jpg"
0.436 "<test_images_dir>/boats on a lake.jpg"
0.431 "<test_images_dir>/books.jpg"
0.654 "<test_images_dir>black cat at night.jpg"
0.595 "<test_images_dir>black cat sleeping on a chair.JPG"
0.582 "<test_images_dir>cat.jpg"
0.579 "<test_images_dir>black kitty.jpg"
0.535 "<test_images_dir>cautious cat.jpg"
0.472 "<test_images_dir>chessboard with rocks.JPG"
0.472 "<test_images_dir>camera.jpg"
0.467 "<test_images_dir>cake.jpg"
0.436 "<test_images_dir>boats on a lake.jpg"
0.431 "<test_images_dir>books.jpg"
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_search.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.261 "<test_images_dir>/black cat at night.jpg"
0.251 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.248 "<test_images_dir>/cat.jpg"
0.247 "<test_images_dir>/black kitty.jpg"
0.244 "<test_images_dir>/cautious cat.jpg"
0.178 "<test_images_dir>/camera.jpg"
0.175 "<test_images_dir>/cake.jpg"
0.171 "<test_images_dir>/chessboard with rocks.JPG"
0.164 "<test_images_dir>/boats on a lake.jpg"
0.161 "<test_images_dir>/bee.jpg"
0.261 "<test_images_dir>black cat at night.jpg"
0.251 "<test_images_dir>black cat sleeping on a chair.JPG"
0.248 "<test_images_dir>cat.jpg"
0.247 "<test_images_dir>black kitty.jpg"
0.244 "<test_images_dir>cautious cat.jpg"
0.178 "<test_images_dir>camera.jpg"
0.175 "<test_images_dir>cake.jpg"
0.171 "<test_images_dir>chessboard with rocks.JPG"
0.164 "<test_images_dir>boats on a lake.jpg"
0.161 "<test_images_dir>bee.jpg"
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_search_by_image.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
0.787 "<test_images_dir>/black kitty.jpg"
0.780 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.744 "<test_images_dir>/black cat at night.jpg"
0.700 "<test_images_dir>/cautious cat.jpg"
0.611 "<test_images_dir>/chessboard with rocks.JPG"
0.564 "<test_images_dir>/bee.jpg"
0.560 "<test_images_dir>/cake.jpg"
0.558 "<test_images_dir>/camera.jpg"
0.531 "<test_images_dir>/books.jpg"
0.531 "<test_images_dir>/boats on a lake.jpg"
0.787 "<test_images_dir>black kitty.jpg"
0.780 "<test_images_dir>black cat sleeping on a chair.JPG"
0.744 "<test_images_dir>black cat at night.jpg"
0.700 "<test_images_dir>cautious cat.jpg"
0.611 "<test_images_dir>chessboard with rocks.JPG"
0.564 "<test_images_dir>bee.jpg"
0.560 "<test_images_dir>cake.jpg"
0.558 "<test_images_dir>camera.jpg"
0.531 "<test_images_dir>books.jpg"
0.531 "<test_images_dir>boats on a lake.jpg"
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_search_by_image_from_url.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
1.000 "<test_images_dir>/cat.jpg"
0.787 "<test_images_dir>/black kitty.jpg"
0.780 "<test_images_dir>/black cat sleeping on a chair.JPG"
0.744 "<test_images_dir>/black cat at night.jpg"
0.700 "<test_images_dir>/cautious cat.jpg"
0.611 "<test_images_dir>/chessboard with rocks.JPG"
0.564 "<test_images_dir>/bee.jpg"
0.560 "<test_images_dir>/cake.jpg"
0.558 "<test_images_dir>/camera.jpg"
0.531 "<test_images_dir>/books.jpg"
1.000 "<test_images_dir>cat.jpg"
0.787 "<test_images_dir>black kitty.jpg"
0.780 "<test_images_dir>black cat sleeping on a chair.JPG"
0.744 "<test_images_dir>black cat at night.jpg"
0.700 "<test_images_dir>cautious cat.jpg"
0.611 "<test_images_dir>chessboard with rocks.JPG"
0.564 "<test_images_dir>bee.jpg"
0.560 "<test_images_dir>cake.jpg"
0.558 "<test_images_dir>camera.jpg"
0.531 "<test_images_dir>books.jpg"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
File "<test_images_dir>/non-existing-file.jpg" not found. Check if you have typos in the filename.
File "<test_images_dir>non-existing-file.jpg" not found. Check if you have typos in the filename.
2 changes: 1 addition & 1 deletion tests/e2e/output_snapshots/test_search_by_not_an_image.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
File "<test_images_dir>/not-an-image.txt" is not an image. You can only use image files or text as queries.
File "<test_images_dir>not-an-image.txt" is not an image. You can only use image files or text as queries.
20 changes: 10 additions & 10 deletions tests/e2e/output_snapshots/test_subtract_queries.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
score filepath
-0.328 "<test_images_dir>/black kitty.jpg"
-0.340 "<test_images_dir>/camera lens.jpg"
-0.341 "<test_images_dir>/books.jpg"
-0.344 "<test_images_dir>/cat.jpg"
-0.366 "<test_images_dir>/cake.jpg"
-0.378 "<test_images_dir>/black cat sleeping on a chair.JPG"
-0.387 "<test_images_dir>/black cat at night.jpg"
-0.388 "<test_images_dir>/camera.jpg"
-0.390 "<test_images_dir>/cautious cat.jpg"
-0.391 "<test_images_dir>/bee.jpg"
-0.328 "<test_images_dir>black kitty.jpg"
-0.340 "<test_images_dir>camera lens.jpg"
-0.341 "<test_images_dir>books.jpg"
-0.344 "<test_images_dir>cat.jpg"
-0.366 "<test_images_dir>cake.jpg"
-0.378 "<test_images_dir>black cat sleeping on a chair.JPG"
-0.387 "<test_images_dir>black cat at night.jpg"
-0.388 "<test_images_dir>camera.jpg"
-0.390 "<test_images_dir>cautious cat.jpg"
-0.391 "<test_images_dir>bee.jpg"
3 changes: 2 additions & 1 deletion tests/e2e/test_rclip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import os
import sys
import tempfile

Expand All @@ -24,7 +25,7 @@ def assert_output_snapshot(test_images_dir: Path, request: pytest.FixtureRequest
yield
out, _ = capsys.readouterr()
snapshot_path = Path(__file__).parent / 'output_snapshots' / f'{request.node.name}.txt'
snapshot = out.replace(str(test_images_dir), '<test_images_dir>')
snapshot = out.replace(str(test_images_dir) + os.path.sep, '<test_images_dir>')
if not snapshot_path.exists():
snapshot_path.write_text(snapshot)
assert snapshot == snapshot_path.read_text()
Expand Down

0 comments on commit 942c428

Please sign in to comment.