Skip to content

Commit a9a3ea1

Browse files
committed
Fixed tests
1 parent 05fe2cb commit a9a3ea1

8 files changed

Lines changed: 32 additions & 32 deletions

tests/test_bit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ def test_bytes(self):
3434
assert Bit(b'\xff\x00\xf0').to_text() == '111111110000000011110000'
3535
assert Bit(b'\xfe\x07\x00').to_text() == '111111100000011100000000'
3636

37-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
37+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3838
def test_ndarray(self):
3939
arr = np.array([True, False, True])
4040
assert Bit(arr).to_list() == [True, False, True]
4141
assert np.array_equal(Bit(arr).to_numpy(), arr)
4242

43-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
43+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
4444
def test_ndarray_unpackbits(self):
4545
arr = np.unpackbits(np.array([254, 7, 0], dtype=np.uint8))
4646
assert Bit(arr).to_text() == '111111100000011100000000'
4747

48-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
48+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
4949
def test_ndarray_uint8(self):
5050
arr = np.array([254, 7, 0], dtype=np.uint8)
5151
with pytest.warns(UserWarning, match='expected elements to be boolean'):
5252
assert Bit(arr).to_text() == '110'
5353

54-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
54+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
5555
def test_ndarray_uint16(self):
5656
arr = np.array([254, 7, 0], dtype=np.uint16)
5757
with pytest.warns(UserWarning, match='expected elements to be boolean'):

tests/test_half_vector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_list_list(self):
2626
HalfVector([[1, 2], [3, 4]]) # ty: ignore[invalid-argument-type]
2727
assert str(error.value) == 'expected list[float]'
2828

29-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
29+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3030
def test_ndarray(self):
3131
arr = np.array([1, 2, 3])
3232
assert HalfVector(arr).to_list() == [1, 2, 3]
@@ -48,7 +48,7 @@ def test_equality(self):
4848
def test_dimensions(self):
4949
assert HalfVector([1, 2, 3]).dimensions() == 3
5050

51-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
51+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
5252
def test_to_numpy_readonly(self):
5353
arr = HalfVector([1, 2, 3]).to_numpy()
5454
with pytest.raises(ValueError) as error:
@@ -58,13 +58,13 @@ def test_to_numpy_readonly(self):
5858
def test_from_text(self):
5959
vec = HalfVector.from_text('[1.5,2,3]')
6060
assert vec.to_list() == [1.5, 2, 3]
61-
if np is not None:
61+
if NUMPY_AVAILABLE:
6262
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
6363

6464
def test_from_binary(self):
6565
data = pack('>HH3e', 3, 0, 1.5, 2, 3)
6666
vec = HalfVector.from_binary(data)
6767
assert vec.to_list() == [1.5, 2, 3]
68-
if np is not None:
68+
if NUMPY_AVAILABLE:
6969
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
7070
assert vec.to_binary() == data

tests/test_pg8000.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_vector(self):
3131
assert res[0][0] == embedding
3232
assert res[1][0] is None
3333

34-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
34+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3535
def test_vector_numpy(self):
3636
embedding = np.array([1.5, 2, 3])
3737
conn.run('INSERT INTO pg8000_items (embedding) VALUES (:embedding), (NULL)', embedding=embedding)

tests/test_psycopg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ def test_vector_binary_format_correct(self):
4646
res = next(conn.execute('SELECT %b::vector::text', (embedding,)))[0]
4747
assert res == '[1.5,2,3]'
4848

49-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
49+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
5050
def test_vector_numpy_binary_format(self):
5151
embedding = np.array([1.5, 2, 3])
5252
res = next(conn.execute('SELECT %b::vector', (embedding,), binary=True))[0]
5353
assert res == Vector(embedding)
5454

55-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
55+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
5656
def test_vector_numpy_text_format(self):
5757
embedding = np.array([1.5, 2, 3])
5858
res = next(conn.execute('SELECT %t::vector', (embedding,)))[0]
5959
assert res == Vector(embedding)
6060

61-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
61+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
6262
def test_vector_numpy_binary_format_non_contiguous(self):
6363
embedding = np.flipud(np.array([1.5, 2, 3]))
6464
assert not embedding.data.contiguous
6565
res = next(conn.execute('SELECT %b::vector', (embedding,)))[0]
6666
assert res == Vector([3, 2, 1.5])
6767

68-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
68+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
6969
def test_vector_numpy_text_format_non_contiguous(self):
7070
embedding = np.flipud(np.array([1.5, 2, 3]))
7171
assert not embedding.data.contiguous

tests/test_psycopg2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_vector(self):
3535
assert res[0][0] == embedding
3636
assert res[1][0] is None
3737

38-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
38+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3939
def test_vector_numpy(self):
4040
embedding = np.array([1.5, 2, 3])
4141
cur.execute('INSERT INTO psycopg2_items (embedding) VALUES (%s), (NULL)', (embedding,))

tests/test_sparse_vector.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TestSparseVector:
1919
def test_list(self):
2020
vec = SparseVector([1, 0, 2, 0, 3, 0])
2121
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
22-
if np is not None:
22+
if NUMPY_AVAILABLE:
2323
assert np.array_equal(vec.to_numpy(), [1, 0, 2, 0, 3, 0])
2424
assert vec.indices() == [0, 2, 4]
2525

@@ -28,7 +28,7 @@ def test_list_dimensions(self):
2828
SparseVector([1, 0, 2, 0, 3, 0], 6) # ty: ignore[invalid-argument-type]
2929
assert str(error.value) == 'extra argument'
3030

31-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
31+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3232
def test_ndarray(self):
3333
vec = SparseVector(np.array([1, 0, 2, 0, 3, 0]))
3434
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
@@ -44,41 +44,41 @@ def test_dict_no_dimensions(self):
4444
SparseVector({0: 1, 2: 2, 4: 3})
4545
assert str(error.value) == 'missing dimensions'
4646

47-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
47+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
4848
def test_coo_array(self):
4949
arr = coo_array(np.array([1, 0, 2, 0, 3, 0]))
5050
vec = SparseVector(arr)
5151
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
5252
assert vec.indices() == [0, 2, 4]
5353

54-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
54+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
5555
def test_coo_array_dimensions(self):
5656
with pytest.raises(ValueError) as error:
5757
SparseVector(coo_array(np.array([1, 0, 2, 0, 3, 0])), 6) # ty: ignore[invalid-argument-type]
5858
assert str(error.value) == 'extra argument'
5959

60-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
60+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
6161
def test_coo_matrix(self):
6262
mat = coo_matrix(np.array([1, 0, 2, 0, 3, 0]))
6363
vec = SparseVector(mat)
6464
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
6565
assert vec.indices() == [0, 2, 4]
6666

67-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
67+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
6868
def test_dok_array(self):
6969
arr = coo_array(np.array([1, 0, 2, 0, 3, 0])).todok()
7070
vec = SparseVector(arr)
7171
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
7272
assert vec.indices() == [0, 2, 4]
7373

74-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
74+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
7575
def test_csr_array(self):
7676
arr = csr_array(np.array([[1, 0, 2, 0, 3, 0]]))
7777
vec = SparseVector(arr)
7878
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
7979
assert vec.indices() == [0, 2, 4]
8080

81-
@pytest.mark.skipif(SCIPY_AVAILABLE, reason='SciPy required')
81+
@pytest.mark.skipif(not SCIPY_AVAILABLE, reason='SciPy required')
8282
def test_csr_matrix(self):
8383
mat = csr_matrix(np.array([1, 0, 2, 0, 3, 0]))
8484
vec = SparseVector(mat)
@@ -104,7 +104,7 @@ def test_indices(self):
104104
def test_values(self):
105105
assert SparseVector([1, 0, 2, 0, 3, 0]).values() == [1, 2, 3]
106106

107-
@pytest.mark.skipif(NUMPY_AVAILABLE or SCIPY_AVAILABLE, reason='NumPy and SciPy required')
107+
@pytest.mark.skipif(not NUMPY_AVAILABLE or not SCIPY_AVAILABLE, reason='NumPy and SciPy required')
108108
def test_to_coo(self):
109109
assert np.array_equal(SparseVector([1, 0, 2, 0, 3, 0]).to_coo().toarray(), [[1, 0, 2, 0, 3, 0]])
110110

@@ -118,7 +118,7 @@ def test_from_text(self):
118118
assert vec.indices() == [0, 2, 4]
119119
assert vec.values() == [1.5, 2, 3]
120120
assert vec.to_list() == [1.5, 0, 2, 0, 3, 0]
121-
if np is not None:
121+
if NUMPY_AVAILABLE:
122122
assert np.array_equal(vec.to_numpy(), [1.5, 0, 2, 0, 3, 0])
123123

124124
def test_from_binary(self):
@@ -128,6 +128,6 @@ def test_from_binary(self):
128128
assert vec.indices() == [0, 2, 4]
129129
assert vec.values() == [1.5, 2, 3]
130130
assert vec.to_list() == [1.5, 0, 2, 0, 3, 0]
131-
if np is not None:
131+
if NUMPY_AVAILABLE:
132132
assert np.array_equal(vec.to_numpy(), [1.5, 0, 2, 0, 3, 0])
133133
assert vec.to_binary() == data

tests/test_sqlalchemy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ def test_bad_dimensions(self, engine):
474474
with pytest.raises(StatementError, match='expected 3 dimensions, not 2'):
475475
session.commit()
476476

477-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
477+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
478478
def test_bad_ndim(self, engine):
479479
item = Item(embedding=np.array([[1, 2, 3]]))
480480
with Session(engine) as session:
481481
session.add(item)
482482
with pytest.raises(StatementError, match='expected ndim to be 1'):
483483
session.commit()
484484

485-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
485+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
486486
def test_bad_dtype(self, engine):
487487
item = Item(embedding=np.array(['one', 'two', 'three']))
488488
with Session(engine) as session:
@@ -671,7 +671,7 @@ async def test_vector_array(self, engine):
671671
item = await session.get_one(Item, 1)
672672
assert item.embeddings == [Vector([1, 2, 3]), Vector([4, 5, 6])]
673673

674-
if np is not None:
674+
if NUMPY_AVAILABLE:
675675
session.add(Item(id=2, embeddings=[np.array([1, 2, 3]), np.array([4, 5, 6])]))
676676
item = await session.get_one(Item, 2)
677677
assert item.embeddings == [Vector([1, 2, 3]), Vector([4, 5, 6])]

tests/test_vector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_list_list(self):
2626
Vector([[1, 2], [3, 4]]) # ty: ignore[invalid-argument-type]
2727
assert str(error.value) == 'expected list[float]'
2828

29-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
29+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3030
def test_ndarray(self):
3131
arr = np.array([1, 2, 3])
3232
assert Vector(arr).to_list() == [1, 2, 3]
@@ -48,7 +48,7 @@ def test_equality(self):
4848
def test_dimensions(self):
4949
assert Vector([1, 2, 3]).dimensions() == 3
5050

51-
@pytest.mark.skipif(NUMPY_AVAILABLE, reason='NumPy required')
51+
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
5252
def test_to_numpy_readonly(self):
5353
arr = Vector([1, 2, 3]).to_numpy()
5454
with pytest.raises(ValueError) as error:
@@ -58,13 +58,13 @@ def test_to_numpy_readonly(self):
5858
def test_from_text(self):
5959
vec = Vector.from_text('[1.5,2,3]')
6060
assert vec.to_list() == [1.5, 2, 3]
61-
if np is not None:
61+
if NUMPY_AVAILABLE:
6262
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
6363

6464
def test_from_binary(self):
6565
data = pack('>HH3f', 3, 0, 1.5, 2, 3)
6666
vec = Vector.from_binary(data)
6767
assert vec.to_list() == [1.5, 2, 3]
68-
if np is not None:
68+
if NUMPY_AVAILABLE:
6969
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
7070
assert vec.to_binary() == data

0 commit comments

Comments
 (0)