Changeset 801


Ignore:
Timestamp:
Jan 31, 2016, 2:51:16 PM (4 years ago)
Author:
cito
Message:

Add documentation and tests for two older methods

transaction() was there since 3.6 and parameter() since 4.0,
but they have never been documented or tested

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/pg/connection.rst

    r798 r801  
    111111the DB-SIG API wrapper to implement a close function.
    112112
     113transaction -- get the current transaction state
     114------------------------------------------------
     115
     116.. method:: Connection.transaction()
     117
     118    Get the current in-transaction status of the server
     119
     120    :returns: the current in-transaction status
     121    :rtype: int
     122    :raises TypeError: too many (any) arguments
     123    :raises TypeError: invalid connection
     124
     125The status returned by this method can be :const:`TRANS_IDLE` (currently idle),
     126:const:`TRANS_ACTIVE` (a command is in progress), :const:`TRANS_INTRANS` (idle,
     127in a valid transaction block), or :const:`TRANS_INERROR` (idle, in a failed
     128transaction block).  :const:`TRANS_UNKNOWN` is reported if the connection is
     129bad.  The status :const:`TRANS_ACTIVE` is reported only when a query has been
     130sent to the server and not yet completed.
     131
     132parameter -- get a current server parameter setting
     133---------------------------------------------------
     134
     135.. method:: Connection.parameter(name)
     136
     137    Looks up a current parameter setting of the server
     138
     139    :param str name: the name of the parameter to look up
     140    :returns: the current setting of the specified parameter
     141    :rtype: str or None
     142    :raises TypeError: too many (any) arguments
     143    :raises TypeError: invalid connection
     144
     145Certain parameter values are reported by the server automatically at
     146connection startup or whenever their values change.  This method can be used
     147to interrogate these settings.  It returns the current value of a parameter
     148if known, or *None* if the parameter is not known.
     149
     150You can use this method to check the settings of important parameters such as
     151`server_version`, `server_encoding`, `client_encoding`, `application_name`,
     152`is_superuser`, `session_authorization`, `DateStyle`, `IntervalStyle`,
     153`TimeZone`, `integer_datetimes`, and `standard_conforming_strings`.
     154
     155Values that are not reported by this method can be requested using
     156:meth:`DB.get_parameter`.
     157
     158.. versionadded:: 4.0
     159
    113160fileno -- returns the socket used to connect to the database
    114161------------------------------------------------------------
  • trunk/docs/contents/pg/db_wrapper.rst

    r799 r801  
    173173to its keys.
    174174
    175 By passing the special name `'all'` as the parameter, you can get a dict
     175By passing the special name ``'all'`` as the parameter, you can get a dict
    176176of all existing configuration parameters.
     177
     178Note that you can request most of the important parameters also using
     179:meth:`Connection.parameter()` which does not involve a database query
     180like it is the case for :meth:`DB.get_parameter` and :meth:`DB.set_parameter`.
    177181
    178182.. versionadded:: 4.2
     
    202206will be taken from the dict.
    203207
    204 By passing the special name `'all'` as the parameter, you can reset
     208By passing the special name ``'all'`` as the parameter, you can reset
    205209all existing settable run-time parameters to their default values.
    206210
  • trunk/docs/contents/pg/module.rst

    r799 r801  
    527527for more information about them. These constants are:
    528528
    529 .. data:: version, __version__
     529.. data:: version
     530.. data:: __version__
    530531
    531532    constants that give the current version
    532533
    533 .. data:: INV_READ, INV_WRITE
     534.. data:: INV_READ
     535.. data:: INV_WRITE
    534536
    535537    large objects access modes,
    536538    used by :meth:`Connection.locreate` and :meth:`LargeObject.open`
    537539
    538 .. data:: SEEK_SET, SEEK_CUR, SEEK_END:
     540.. data:: SEEK_SET
     541.. data:: SEEK_CUR
     542.. data:: SEEK_END
    539543
    540544    positional flags, used by :meth:`LargeObject.seek`
     545
     546.. data:: TRANS_IDLE
     547.. data:: TRANS_ACTIVE
     548.. data:: TRANS_INTRANS
     549.. data:: TRANS_INERROR
     550.. data:: TRANS_UNKNOWN
     551
     552    transaction states, used by :meth:`Connection.transaction`
  • trunk/tests/test_classic_connection.py

    r798 r801  
    255255        self.assertIsInstance(r, int)
    256256        self.assertGreaterEqual(r, 0)
     257
     258    def testMethodTransaction(self):
     259        transaction = self.connection.transaction
     260        self.assertRaises(TypeError, transaction, None)
     261        self.assertEqual(transaction(), pg.TRANS_IDLE)
     262        self.connection.query('begin')
     263        self.assertEqual(transaction(), pg.TRANS_INTRANS)
     264        self.connection.query('rollback')
     265        self.assertEqual(transaction(), pg.TRANS_IDLE)
     266
     267    def testMethodParameter(self):
     268        parameter = self.connection.parameter
     269        query = self.connection.query
     270        self.assertRaises(TypeError, parameter)
     271        r = parameter('this server setting does not exist')
     272        self.assertIsNone(r)
     273        s = query('show server_version').getresult()[0][0].upper()
     274        self.assertIsNotNone(s)
     275        r = parameter('server_version')
     276        self.assertEqual(r, s)
     277        s = query('show server_encoding').getresult()[0][0].upper()
     278        self.assertIsNotNone(s)
     279        r = parameter('server_encoding')
     280        self.assertEqual(r, s)
     281        s = query('show client_encoding').getresult()[0][0].upper()
     282        self.assertIsNotNone(s)
     283        r = parameter('client_encoding')
     284        self.assertEqual(r, s)
     285        s = query('show server_encoding').getresult()[0][0].upper()
     286        self.assertIsNotNone(s)
     287        r = parameter('server_encoding')
     288        self.assertEqual(r, s)
    257289
    258290
Note: See TracChangeset for help on using the changeset viewer.