File: test_cast.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 (19 lines) | stat: -rw-r--r-- 653 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
# 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 Cast, Column, Table


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

    def test_cast(self):
        for cast in [Cast(self.column, 'int'), self.column.cast('int')]:
            self.assertEqual(str(cast), 'CAST("c" AS int)')
            self.assertEqual(cast.params, ())

    def test_cast_no_expression(self):
        cast = Cast(1.1, 'int')
        self.assertEqual(str(cast), 'CAST(%s AS int)')
        self.assertEqual(cast.params, (1.1,))