tests/test_rowdict.py
author Radek Brich <brich.radek@ifortuna.cz>
Tue, 06 May 2014 18:34:38 +0200
changeset 99 245646538743
parent 81 f709b1c7ca0c
child 104 d8ff52a0390f
permissions -rw-r--r--
Update runquery tool: Add --one-query-per-line parameter.

#!/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.values()
        self.assertEqual(name, 'hello')

    def test_rowdict_repr(self):
        repr_text = "RowDict([('id', 123), ('name', 'hello')])"
        self.assertEqual(repr(self.rowdict), repr_text)
        self.assertEqual(str(self.rowdict), repr_text)


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