File: test_as.py

package info (click to toggle)
python-sql 1.4.0-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 436 kB
  • sloc: python: 3,956; sh: 9; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file is part of python-sql.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import unittest

from sql import As, Column, Flavor, Table


class TestAs(unittest.TestCase):
    table = Table('t')
    column = Column(table, 'c')

    def test_as(self):
        self.assertEqual(str(As(self.column, 'foo')), '"foo"')

    def test_as_select(self):
        query = self.table.select(self.column.as_('foo'))
        self.assertEqual(str(query), 'SELECT "a"."c" AS "foo" FROM "t" AS "a"')
        self.assertEqual(tuple(query.params), ())

    def test_no_as(self):
        query = self.table.select(self.column.as_('foo'))
        try:
            Flavor.set(Flavor(no_as=True))
            self.assertEqual(str(query), 'SELECT "a"."c" "foo" FROM "t" "a"')
            self.assertEqual(tuple(query.params), ())
        finally:
            Flavor.set(Flavor())