File: test_from_item.py

package info (click to toggle)
python-sql 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: python: 5,016; sh: 9; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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 AliasManager, Column, From, FromItem


class TestFromItem(unittest.TestCase):

    def test_from_item(self):
        from_item = FromItem()

        with AliasManager():
            self.assertFalse(from_item.has_alias)
            from_item.alias
            self.assertTrue(from_item.has_alias)

    def test_get_column(self):
        from_item = FromItem()

        foo = from_item.foo

        self.assertIsInstance(foo, Column)
        self.assertEqual(foo.name, 'foo')

    def test_get_invalid_column(self):
        from_item = FromItem()

        with self.assertRaises(AttributeError):
            from_item.__foo__

    def test_add(self):
        from_item1 = FromItem()
        from_item2 = FromItem()

        from_ = from_item1 + from_item2

        self.assertIsInstance(from_, From)
        self.assertEqual(from_, [from_item1, from_item2])

    def test_invalid_add(self):
        from_item = FromItem()

        with self.assertRaises(TypeError):
            from_item + 'foo'