tests/test_rowdict.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Sep 2012 12:08:47 +0200
changeset 48 b82c7c2fb5af
child 81 f709b1c7ca0c
permissions -rw-r--r--
PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.

#!/usr/bin/env python3

from pgtoolkit.pgmanager import RowDict

import unittest


class TestRowDict(unittest.TestCase):
    def setUp(self):
        self.rowdict = RowDict([('id', 123), ('name', 'hello')])

    def test_rowdict_as_kwargs(self):
        rowdict_id = (lambda **kwargs: kwargs['id']) (**self.rowdict)
        self.assertEqual(rowdict_id, 123)

    def test_rowdict_key_access(self):
        self.assertEqual(self.rowdict['id'], 123)

    def test_rowdict_attr_access(self):
        self.assertEqual(self.rowdict.name, 'hello')

    def test_rowdict_index_access(self):
        self.assertEqual(self.rowdict[0], 123)

    def test_rowdict_unpack(self):
        _id, name = self.rowdict
        self.assertEqual(name, 'hello')


if __name__ == '__main__':
    unittest.main()