tests/test_rowdict.py
changeset 48 b82c7c2fb5af
child 81 f709b1c7ca0c
equal deleted inserted replaced
47:bb8c729ae6ce 48:b82c7c2fb5af
       
     1 #!/usr/bin/env python3
       
     2 
       
     3 from pgtoolkit.pgmanager import RowDict
       
     4 
       
     5 import unittest
       
     6 
       
     7 
       
     8 class TestRowDict(unittest.TestCase):
       
     9     def setUp(self):
       
    10         self.rowdict = RowDict([('id', 123), ('name', 'hello')])
       
    11 
       
    12     def test_rowdict_as_kwargs(self):
       
    13         rowdict_id = (lambda **kwargs: kwargs['id']) (**self.rowdict)
       
    14         self.assertEqual(rowdict_id, 123)
       
    15 
       
    16     def test_rowdict_key_access(self):
       
    17         self.assertEqual(self.rowdict['id'], 123)
       
    18 
       
    19     def test_rowdict_attr_access(self):
       
    20         self.assertEqual(self.rowdict.name, 'hello')
       
    21 
       
    22     def test_rowdict_index_access(self):
       
    23         self.assertEqual(self.rowdict[0], 123)
       
    24 
       
    25     def test_rowdict_unpack(self):
       
    26         _id, name = self.rowdict
       
    27         self.assertEqual(name, 'hello')
       
    28 
       
    29 
       
    30 if __name__ == '__main__':
       
    31     unittest.main()