Skip to content

Commit 398d6d7

Browse files
committed
misplaced some tests
1 parent 7e6960f commit 398d6d7

File tree

1 file changed

+153
-154
lines changed

1 file changed

+153
-154
lines changed

tests/test_suite.py

Lines changed: 153 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@
2525

2626
from sqlalchemy import __version__ as sqlalchemy_version
2727

28+
if sqlalchemy_version.startswith("2."):
29+
from sqlalchemy.testing.suite import (
30+
BizarroCharacterFKResolutionTest as _BizarroCharacterFKResolutionTest,
31+
)
32+
33+
class BizarroCharacterFKResolutionTest(_BizarroCharacterFKResolutionTest):
34+
@testing.combinations(
35+
("id",), ("(3)",), ("col%p",), ("[brack]",), argnames="columnname"
36+
)
37+
@testing.variation("use_composite", [True, False])
38+
@testing.combinations(
39+
("plain",),
40+
# ("(2)",), not in IRIS
41+
("per % cent",),
42+
("[brackets]",),
43+
argnames="tablename",
44+
)
45+
def test_fk_ref(
46+
self, connection, metadata, use_composite, tablename, columnname
47+
):
48+
super().test_fk_ref(
49+
connection, metadata, use_composite, tablename, columnname
50+
)
51+
2852

2953
class CompoundSelectTest(_CompoundSelectTest):
3054
@pytest.mark.skip()
@@ -269,175 +293,150 @@ def test_expect_bytes(self):
269293
)
270294

271295

272-
if sqlalchemy_version.startswith("2."):
273-
from sqlalchemy.testing.suite import (
274-
BizarroCharacterFKResolutionTest as _BizarroCharacterFKResolutionTest,
275-
)
296+
class IRISListBuildTest(fixtures.TablesTest):
297+
__backend__ = True
276298

277-
class BizarroCharacterFKResolutionTest(_BizarroCharacterFKResolutionTest):
278-
@testing.combinations(
279-
("id",), ("(3)",), ("col%p",), ("[brack]",), argnames="columnname"
280-
)
281-
@testing.variation("use_composite", [True, False])
282-
@testing.combinations(
283-
("plain",),
284-
# ("(2)",), not in IRIS
285-
("per % cent",),
286-
("[brackets]",),
287-
argnames="tablename",
299+
@classmethod
300+
def define_tables(cls, metadata):
301+
Table(
302+
"data",
303+
metadata,
304+
Column("val", IRISListBuild(10, float)),
288305
)
289-
def test_fk_ref(
290-
self, connection, metadata, use_composite, tablename, columnname
291-
):
292-
super().test_fk_ref(
293-
connection, metadata, use_composite, tablename, columnname
294-
)
295-
296-
class IRISListBuildTest(fixtures.TablesTest):
297-
__backend__ = True
298306

299-
@classmethod
300-
def define_tables(cls, metadata):
301-
Table(
302-
"data",
303-
metadata,
304-
Column("val", IRISListBuild(10, float)),
307+
@classmethod
308+
def fixtures(cls):
309+
return dict(
310+
data=(
311+
("val",),
312+
([1.0] * 50,),
313+
([1.23] * 50,),
314+
([i for i in range(0, 50)],),
315+
(None,),
305316
)
317+
)
306318

307-
@classmethod
308-
def fixtures(cls):
309-
return dict(
310-
data=(
311-
("val",),
312-
([1.0] * 50,),
313-
([1.23] * 50,),
314-
([i for i in range(0, 50)],),
315-
(None,),
316-
)
317-
)
319+
def _assert_result(self, select, result):
320+
with config.db.connect() as conn:
321+
eq_(conn.execute(select).fetchall(), result)
318322

319-
def _assert_result(self, select, result):
320-
with config.db.connect() as conn:
321-
eq_(conn.execute(select).fetchall(), result)
323+
def test_listbuild(self):
324+
self._assert_result(
325+
select(self.tables.data),
326+
[
327+
([1.0] * 50,),
328+
([1.23] * 50,),
329+
([i for i in range(0, 50)],),
330+
(None,),
331+
],
332+
)
333+
self._assert_result(
334+
select(self.tables.data).where(self.tables.data.c.val == [1.0] * 50),
335+
[
336+
([1.0] * 50,),
337+
],
338+
)
322339

323-
def test_listbuild(self):
324-
self._assert_result(
325-
select(self.tables.data),
326-
[
327-
([1.0] * 50,),
328-
([1.23] * 50,),
329-
([i for i in range(0, 50)],),
330-
(None,),
331-
],
332-
)
333-
self._assert_result(
334-
select(self.tables.data).where(self.tables.data.c.val == [1.0] * 50),
335-
[
336-
([1.0] * 50,),
337-
],
338-
)
340+
self._assert_result(
341+
select(
342+
self.tables.data,
343+
self.tables.data.c.val.func("$listsame", [1.0] * 50).label("same"),
344+
).limit(1),
345+
[
346+
([1.0] * 50, 1),
347+
],
348+
)
339349

340-
self._assert_result(
341-
select(
342-
self.tables.data,
343-
self.tables.data.c.val.func("$listsame", [1.0] * 50).label("same"),
344-
).limit(1),
345-
[
346-
([1.0] * 50, 1),
347-
],
348-
)
349350

350-
class IRISVectorTest(fixtures.TablesTest):
351-
__backend__ = True
351+
class IRISVectorTest(fixtures.TablesTest):
352+
__backend__ = True
352353

353-
__requires__ = ("iris_vector",)
354+
__requires__ = ("iris_vector",)
354355

355-
@classmethod
356-
def define_tables(cls, metadata):
357-
Table(
358-
"data",
359-
metadata,
360-
Column("id", INTEGER),
361-
Column("emb", IRISVector(3, float)),
362-
)
356+
@classmethod
357+
def define_tables(cls, metadata):
358+
Table(
359+
"data",
360+
metadata,
361+
Column("id", INTEGER),
362+
Column("emb", IRISVector(3, float)),
363+
)
363364

364-
@classmethod
365-
def fixtures(cls):
366-
return dict(
367-
data=(
368-
(
369-
"id",
370-
"emb",
371-
),
372-
(
373-
1,
374-
[1, 1, 1],
375-
),
376-
(
377-
2,
378-
[2, 2, 2],
379-
),
380-
(
381-
3,
382-
[1, 1, 2],
383-
),
384-
)
365+
@classmethod
366+
def fixtures(cls):
367+
return dict(
368+
data=(
369+
(
370+
"id",
371+
"emb",
372+
),
373+
(
374+
1,
375+
[1, 1, 1],
376+
),
377+
(
378+
2,
379+
[2, 2, 2],
380+
),
381+
(
382+
3,
383+
[1, 1, 2],
384+
),
385385
)
386+
)
386387

387-
def _assert_result(self, select, result):
388-
with config.db.connect() as conn:
389-
eq_(conn.execute(select).fetchall(), result)
388+
def _assert_result(self, select, result):
389+
with config.db.connect() as conn:
390+
eq_(conn.execute(select).fetchall(), result)
390391

391-
def test_vector(self):
392-
self._assert_result(
393-
select(self.tables.data.c.emb),
394-
[
395-
([1, 1, 1],),
396-
([2, 2, 2],),
397-
([1, 1, 2],),
398-
],
399-
)
400-
self._assert_result(
401-
select(self.tables.data.c.id).where(
402-
self.tables.data.c.emb == [2, 2, 2]
403-
),
404-
[
405-
(2,),
406-
],
407-
)
392+
def test_vector(self):
393+
self._assert_result(
394+
select(self.tables.data.c.emb),
395+
[
396+
([1, 1, 1],),
397+
([2, 2, 2],),
398+
([1, 1, 2],),
399+
],
400+
)
401+
self._assert_result(
402+
select(self.tables.data.c.id).where(self.tables.data.c.emb == [2, 2, 2]),
403+
[
404+
(2,),
405+
],
406+
)
408407

409-
def test_cosine(self):
410-
self._assert_result(
411-
select(
412-
self.tables.data.c.id,
413-
).order_by(self.tables.data.c.emb.cosine([1, 1, 1])),
414-
[
415-
(1,),
416-
(2,),
417-
(3,),
418-
],
419-
)
408+
def test_cosine(self):
409+
self._assert_result(
410+
select(
411+
self.tables.data.c.id,
412+
).order_by(self.tables.data.c.emb.cosine([1, 1, 1])),
413+
[
414+
(1,),
415+
(2,),
416+
(3,),
417+
],
418+
)
420419

421-
def test_cosine_distance(self):
422-
self._assert_result(
423-
select(
424-
self.tables.data.c.id,
425-
).order_by(1 - self.tables.data.c.emb.cosine_distance([1, 1, 1])),
426-
[
427-
(1,),
428-
(2,),
429-
(3,),
430-
],
431-
)
420+
def test_cosine_distance(self):
421+
self._assert_result(
422+
select(
423+
self.tables.data.c.id,
424+
).order_by(1 - self.tables.data.c.emb.cosine_distance([1, 1, 1])),
425+
[
426+
(1,),
427+
(2,),
428+
(3,),
429+
],
430+
)
432431

433-
def test_max_inner_product(self):
434-
self._assert_result(
435-
select(
436-
self.tables.data.c.id,
437-
).order_by(self.tables.data.c.emb.max_inner_product([1, 1, 1])),
438-
[
439-
(1,),
440-
(3,),
441-
(2,),
442-
],
443-
)
432+
def test_max_inner_product(self):
433+
self._assert_result(
434+
select(
435+
self.tables.data.c.id,
436+
).order_by(self.tables.data.c.emb.max_inner_product([1, 1, 1])),
437+
[
438+
(1,),
439+
(3,),
440+
(2,),
441+
],
442+
)

0 commit comments

Comments
 (0)