async def test_log(conn, capsys): a = await conn.fetchval_b('SELECT :a', print_=True, __timeout=12, a=funcs.cast(5, 'int') * 5) assert a == 25 assert 'SELECT' in capsys.readouterr().out
def select(self) -> Select: if self.method == Method.retrieve: event_link = Func('event_link', V('cat.slug'), V('e.slug'), V('e.public'), funcs.cast(self.settings.auth_key, 'TEXT')).as_('link') return Select(self.retrieve_fields + (event_link, )) return super().select()
async def test_logic(conn, capsys): a, b, c, d = await conn.fetchrow_b('SELECT :a, :b, :c, :d::int', a=funcs.cast(5, 'int') * 5, b=funcs.sqrt(676), c=S('a').cat('b'), d=987_654) assert a == 25 assert b == 26 assert c == 'ab' assert d == 987_654 assert 'SELECT' not in capsys.readouterr().out
async def test_log_callable(conn): logged_message = None def foobar(arg): nonlocal logged_message logged_message = arg a = await conn.fetchval_b('SELECT :a', print_=foobar, __timeout=12, a=funcs.cast(5, 'int') * 5) assert a == 25 assert 'SELECT' in logged_message
async def test_coloured_callable(conn): logged_message = None def foobar(arg): nonlocal logged_message logged_message = arg foobar.formatted = True a = await conn.fetchval_b('SELECT :a', print_=foobar, __timeout=12, a=funcs.cast(5, 'int') * 5) assert a == 25 assert 'SELECT' in logged_message assert '\x1b[' in logged_message
async def test_print(conn, capsys): query, params = conn.print_b('SELECT :a', a=funcs.cast(5, 'int') * 5) assert query == 'SELECT $1::int * $2' assert params == [5, 5] assert 'SELECT' in capsys.readouterr().out
async def test_substring_for(conn): a = await conn.fetchval_b('SELECT :a', a=funcs.substring('Samuel', funcs.cast(2, 'int'), funcs.cast(3, 'int'))) assert a == 'amu'