MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_aggregate_strings_execute

Method test_aggregate_strings_execute

test/sql/test_functions.py:1541–1602  ·  view source on GitHub ↗
(
        self,
        connection,
        metadata,
        unicode_value,
        unicode_separator,
        use_order_by,
    )

Source from the content-addressed store, hash-verified

1539 ["postgresql", "sqlite", "mysql", "mariadb", "oracle", "mssql"]
1540 )
1541 def test_aggregate_strings_execute(
1542 self,
1543 connection,
1544 metadata,
1545 unicode_value,
1546 unicode_separator,
1547 use_order_by,
1548 ):
1549 values_t = Table(
1550 "values",
1551 metadata,
1552 Column("value", String(42)),
1553 Column("unicode_value", Unicode(42)),
1554 )
1555 metadata.create_all(connection)
1556 connection.execute(
1557 values_t.insert(),
1558 [
1559 {"value": "a", "unicode_value": "b 測試"},
1560 {"value": "b", "unicode_value": "c téble2"},
1561 {"value": None, "unicode_value": None}, # ignored
1562 {"value": "c", "unicode_value": "a 🐍 su"},
1563 ],
1564 )
1565
1566 if unicode_separator:
1567 separator = " 🐍試 "
1568 else:
1569 separator = " and "
1570
1571 if unicode_value:
1572 col = values_t.c.unicode_value
1573 if use_order_by:
1574 expected = separator.join(["c téble2", "b 測試", "a 🐍 su"])
1575 else:
1576 expected = separator.join(["b 測試", "c téble2", "a 🐍 su"])
1577 else:
1578 col = values_t.c.value
1579 if use_order_by:
1580 expected = separator.join(["c", "b", "a"])
1581 else:
1582 expected = separator.join(["a", "b", "c"])
1583
1584 # to join on a unicode separator, source string has to be unicode,
1585 # so cast(). SQL Server will raise otherwise
1586 if unicode_separator:
1587 col = cast(col, Unicode(42))
1588
1589 if use_order_by:
1590 value = connection.execute(
1591 select(
1592 func.aggregate_strings(col, separator).aggregate_order_by(
1593 col.desc()
1594 )
1595 )
1596 ).scalar_one()
1597 else:
1598 value = connection.execute(

Callers

nothing calls this directly

Calls 15

TableClass · 0.90
ColumnClass · 0.90
StringClass · 0.90
UnicodeClass · 0.90
castFunction · 0.90
selectFunction · 0.90
eq_Function · 0.90
create_allMethod · 0.80
aggregate_stringsMethod · 0.80
executeMethod · 0.45
insertMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected