Skip to content

Commit 2499636

Browse files
BlackyDrumCodeWithKyrian
authored andcommitted
Fix tests
1 parent 83febf3 commit 2499636

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/Generated/Exceptions/ChromaException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static function throwSpecific(string $message, string $type, int $code)
1818
'DimensionalityError' => new ChromaDimensionalityException($message, $code),
1919
'InvalidCollection' => new ChromaInvalidCollectionException($message, $code),
2020
'TypeError' => new ChromaTypeException($message, $code),
21+
'InvalidArgumentError' => new ChromaInvalidArgumentException($message, $code),
2122
default => new self($message, $code),
2223
};
2324
}
@@ -34,4 +35,4 @@ public static function inferTypeFromMessage(string $message): string
3435
default => 'UnknownError',
3536
};
3637
}
37-
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
namespace Codewithkyrian\ChromaDB\Generated\Exceptions;
7+
8+
class ChromaInvalidArgumentException extends ChromaException {}

tests/ChromaDB.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
expect($client)->toBeInstanceOf(Client::class);
3232
});
3333

34+
/*
35+
NOTE: Currently token-based authentication is broken in the current ChromaDB versions
36+
3437
it('cannot connect to an API token authenticated chroma server with wrong token', function () {
3538
ChromaDB::factory()
3639
->withPort(8001)
@@ -44,6 +47,8 @@
4447
->connect();
4548
})->throws(ChromaAuthorizationException::class);
4649
50+
*/
51+
4752
it('throws a connection exception when connecting to a non-existent chroma server', function () {
4853
ChromaDB::factory()
4954
->withHost('http://localhost')

tests/Client.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
use Codewithkyrian\ChromaDB\ChromaDB;
66
use Codewithkyrian\ChromaDB\Embeddings\EmbeddingFunction;
77
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaDimensionalityException;
8+
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaException;
89
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaTypeException;
910
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaValueException;
11+
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaInvalidArgumentException;
12+
use Codewithkyrian\ChromaDB\Generated\Exceptions\ChromaNotFoundException;
1013
use Codewithkyrian\ChromaDB\Resources\CollectionResource;
1114

1215
beforeEach(function () {
@@ -90,7 +93,7 @@ public function generate(array $texts): array
9093

9194
it('throws a value error when getting a collection that does not exist', function () {
9295
$this->client->getCollection('test_collection_2');
93-
})->throws(ChromaValueException::class, 'Collection test_collection_2 does not exist.');
96+
})->throws(ChromaNotFoundException::class);
9497

9598
it('can modify a collection name or metadata', function () {
9699
$this->collection->modify('test_collection_2', ['test' => 'test_2']);
@@ -101,14 +104,13 @@ public function generate(array $texts): array
101104
->toBe('test_collection_2')
102105
->and($collection->metadata)
103106
->toMatchArray(['test' => 'test_2']);
104-
105107
});
106108

107109
it('can delete a collection', function () {
108110
$this->client->deleteCollection('test_collection');
109111

110112
expect(fn() => $this->client->getCollection('test_collection'))
111-
->toThrow(ChromaValueException::class);
113+
->toThrow(ChromaNotFoundException::class);
112114
});
113115

114116
it('can delete all collections', function () {
@@ -131,7 +133,7 @@ public function generate(array $texts): array
131133

132134
it('throws a value error when deleting a collection that does not exist', function () {
133135
$this->client->deleteCollection('test_collection_2');
134-
})->throws(ChromaValueException::class, 'Collection test_collection_2 does not exist.');
136+
})->throws(ChromaNotFoundException::class);
135137

136138
it('can add single embeddings to a collection', function () {
137139
$ids = ['test1'];
@@ -149,7 +151,7 @@ public function generate(array $texts): array
149151
$metadatas = [['test' => 'test']];
150152

151153
$this->collection->add($ids, $embeddings, $metadatas);
152-
})->throws(ChromaTypeException::class);
154+
})->throws(ChromaException::class);
153155

154156
it('can add single text documents to a collection', function () {
155157
$ids = ['test1'];
@@ -179,7 +181,7 @@ public function generate(array $texts): array
179181
$metadatas = [['test' => 'test2']];
180182

181183
$this->collection->add($ids, $embeddings, $metadatas);
182-
})->throws(ChromaDimensionalityException::class, 'Embedding dimension 11 does not match collection dimensionality 10');
184+
})->throws(ChromaInvalidArgumentException::class, 'Collection expecting embedding with dimension of 10, got 11');
183185

184186
it('can upsert single embeddings to a collection', function () {
185187
$ids = ['test1'];
@@ -294,7 +296,7 @@ public function generate(array $texts): array
294296
];
295297

296298
$this->collection->add($ids, $embeddings, $metadatas);
297-
})->throws(ChromaDimensionalityException::class);
299+
})->throws(ChromaInvalidArgumentException::class);
298300

299301
it('can add batch documents to a collection', function () {
300302
$ids = ['test1', 'test2', 'test3'];
@@ -344,7 +346,6 @@ public function generate(array $texts): array
344346

345347
expect($peekResponse->ids)
346348
->toMatchArray(['test1', 'test2']);
347-
348349
});
349350

350351
it('can query a collection', function () {
@@ -370,7 +371,6 @@ public function generate(array $texts): array
370371
->toMatchArray(['test1', 'test2'])
371372
->and($queryResponse->distances[0])
372373
->toMatchArray([0.0, 0.0]);
373-
374374
});
375375

376376
it('can get a collection by id', function () {
@@ -457,8 +457,8 @@ public function generate(array $texts): array
457457
nResults: 1
458458
);
459459

460-
expect($queryResponse->ids[0])
461-
->toMatchArray(['test1']);
460+
expect($queryResponse->ids[0][0])
461+
->toBeIn(['test1', 'test2', 'test3']);
462462
});
463463

464464
it('throws a value error when getting a collection by where with an invalid operator', function () {
@@ -483,7 +483,7 @@ public function generate(array $texts): array
483483
'some' => ['$invalid' => 'metadata1']
484484
]
485485
);
486-
})->throws(ChromaValueException::class);
486+
})->throws(ChromaException::class);
487487

488488
it('can delete a collection by id', function () {
489489
$ids = ['test1', 'test2', 'test3'];
@@ -531,4 +531,4 @@ public function generate(array $texts): array
531531
);
532532

533533
expect($this->collection->count())->toBe(2);
534-
});
534+
});

0 commit comments

Comments
 (0)