Ejemplo n.º 1
0
def test():
    import journal
    # journal.debug("postgres.init").active = True
    # journal.debug("postgres.connection").active = True
    # journal.debug("postgres.execution").active = True
    # journal.debug("postgres.conversions").active = True

    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # execute a command
    command = "SELECT datname FROM pg_database WHERE datname='postgres'"
    # submit it for asynchronous processing
    pyrepg.submit(connection, command)

    # loop until the entire result has been assembled
    while pyrepg.busy(connection):
        pyrepg.consume(connection)

    # retrieve it
    result = pyrepg.retrieve(connection)
    # check that we got what we expected
    assert result == (('datname',), ('postgres',))

    # call retrieve again; this time there should be nothing to get
    result = pyrepg.retrieve(connection)
    assert result == None

    # and return the connection and the resulting tuple
    return connection, result
Ejemplo n.º 2
0
def test():
    import journal
    # journal.debug("postgres.init").active = True
    # journal.debug("postgres.connection").active = True
    # journal.debug("postgres.execution").active = True
    # journal.debug("postgres.conversions").active = True

    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # execute a command
    command = "SELECT datname FROM pg_database WHERE datname='postgres'"
    # submit it for asynchronous processing
    pyrepg.submit(connection, command)

    # loop until the entire result has been assembled
    while pyrepg.busy(connection):
        pyrepg.consume(connection)

    # retrieve it
    result = pyrepg.retrieve(connection)
    # check that we got what we expected
    assert result == (('datname', ), ('postgres', ))

    # call retrieve again; this time there should be nothing to get
    result = pyrepg.retrieve(connection)
    assert result == None

    # and return the connection and the resulting tuple
    return connection, result
Ejemplo n.º 3
0
def test():
    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # and return it
    return connection
Ejemplo n.º 4
0
def test():
    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # and return it
    return connection
Ejemplo n.º 5
0
def test():
    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # execute a command
    try:
        pyrepg.execute(connection, "no-such-command")
        assert False
    except pyrepg.ProgrammingError:
        pass

    # and return it
    return connection
def test():
    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # execute a command
    try:
        pyrepg.execute(connection, "no-such-command")
        assert False
    except pyrepg.ProgrammingError:
        pass

    # and return it
    return connection
Ejemplo n.º 7
0
def test():
    # import journal
    # journal.debug("postgres.init").active = True
    # journal.debug("postgres.connection").active = True
    # journal.debug("postgres.execution").active = True

    from pyre.extensions import postgres as pyrepg
    # initialize the module exceptions
    import pyre.db.exceptions as exceptions
    pyrepg.registerExceptions(exceptions)

    # make a connection
    connection = pyrepg.connect("dbname=postgres")
    # execute a command
    command = "SELECT datname FROM pg_database WHERE datname='postgres'"
    result = pyrepg.execute(connection, command)
    # check that we got what we expected
    assert result == (('datname', ), ('postgres', ))

    # and return the connection and the resulting tuple
    return connection, result
Ejemplo n.º 8
0
def test():
    # access the relevant modules
    from pyre.extensions import postgres as pyrepg
    import pyre.db.exceptions as exceptions
    # initialize the module exceptions manually
    # this is normally done automatically when a client first requests a connection to the
    # database back end
    pyrepg.registerExceptions(exceptions)

    # now check
    # make sure the exception object is accessible
    warning = pyrepg.Warning
    # make sure it is decorated correctly
    assert warning.__name__ == 'Warning'
    assert warning.__module__ == 'pyre.db.exceptions'
    assert warning.__bases__ == (exceptions.FrameworkError,)
    # verify it can be caught
    try:
        raise pyrepg.Warning('a generic database warning')
    except pyrepg.Warning as warning:
        pass

    # make sure the exception object is accessible
    error = pyrepg.Error
    # make sure it is decorated correctly
    assert error.__name__ == 'Error'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (exceptions.FrameworkError,)
    # verify it can be caught
    try:
        raise pyrepg.Error('a generic database error')
    except pyrepg.Error as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.InterfaceError
    # make sure it is decorated correctly
    assert error.__name__ == 'InterfaceError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.Error,)
    # verify it can be caught
    try:
        raise pyrepg.InterfaceError('a generic database error')
    except pyrepg.InterfaceError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.DatabaseError
    # make sure it is decorated correctly
    assert error.__name__ == 'DatabaseError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.Error,)
    # verify it can be caught
    try:
        raise pyrepg.DatabaseError('a generic database error')
    except pyrepg.DatabaseError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.DataError
    # make sure it is decorated correctly
    assert error.__name__ == 'DataError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.DataError('a generic database error')
    except pyrepg.DataError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.OperationalError
    # make sure it is decorated correctly
    assert error.__name__ == 'OperationalError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.OperationalError('a generic database error')
    except pyrepg.OperationalError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.IntegrityError
    # make sure it is decorated correctly
    assert error.__name__ == 'IntegrityError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.IntegrityError('a generic database error')
    except pyrepg.IntegrityError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.InternalError
    # make sure it is decorated correctly
    assert error.__name__ == 'InternalError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.InternalError('a generic database error')
    except pyrepg.InternalError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.ProgrammingError
    # make sure it is decorated correctly
    assert error.__name__ == 'ProgrammingError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.ProgrammingError(diagnostic='a generic database error', command='none')
    except pyrepg.ProgrammingError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.NotSupportedError
    # make sure it is decorated correctly
    assert error.__name__ == 'NotSupportedError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.NotSupportedError('a generic database error')
    except pyrepg.NotSupportedError as error:
        pass

    return
Ejemplo n.º 9
0
def test():
    # access the relevant modules
    from pyre.extensions import postgres as pyrepg
    import pyre.db.exceptions as exceptions
    # initialize the module exceptions manually
    # this is normally done automatically when a client first requests a connection to the
    # database back end
    pyrepg.registerExceptions(exceptions)

    # now check
    # make sure the exception object is accessible
    warning = pyrepg.Warning
    # make sure it is decorated correctly
    assert warning.__name__ == 'Warning'
    assert warning.__module__ == 'pyre.db.exceptions'
    assert warning.__bases__ == (exceptions.FrameworkError,)
    # verify it can be caught
    try:
        raise pyrepg.Warning('a generic database warning')
    except pyrepg.Warning as warning:
        pass

    # make sure the exception object is accessible
    error = pyrepg.Error
    # make sure it is decorated correctly
    assert error.__name__ == 'Error'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (exceptions.FrameworkError,)
    # verify it can be caught
    try:
        raise pyrepg.Error('a generic database error')
    except pyrepg.Error as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.InterfaceError
    # make sure it is decorated correctly
    assert error.__name__ == 'InterfaceError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.Error,)
    # verify it can be caught
    try:
        raise pyrepg.InterfaceError('a generic database error')
    except pyrepg.InterfaceError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.DatabaseError
    # make sure it is decorated correctly
    assert error.__name__ == 'DatabaseError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.Error,)
    # verify it can be caught
    try:
        raise pyrepg.DatabaseError('a generic database error')
    except pyrepg.DatabaseError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.DataError
    # make sure it is decorated correctly
    assert error.__name__ == 'DataError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.DataError('a generic database error')
    except pyrepg.DataError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.OperationalError
    # make sure it is decorated correctly
    assert error.__name__ == 'OperationalError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.OperationalError('a generic database error')
    except pyrepg.OperationalError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.IntegrityError
    # make sure it is decorated correctly
    assert error.__name__ == 'IntegrityError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.IntegrityError('a generic database error')
    except pyrepg.IntegrityError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.InternalError
    # make sure it is decorated correctly
    assert error.__name__ == 'InternalError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.InternalError('a generic database error')
    except pyrepg.InternalError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.ProgrammingError
    # make sure it is decorated correctly
    assert error.__name__ == 'ProgrammingError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.ProgrammingError(diagnostic='a generic database error', command='none')
    except pyrepg.ProgrammingError as error:
        pass

    # make sure the exception object is accessible
    error = pyrepg.NotSupportedError
    # make sure it is decorated correctly
    assert error.__name__ == 'NotSupportedError'
    assert error.__module__ == 'pyre.db.exceptions'
    assert error.__bases__ == (pyrepg.DatabaseError,)
    # verify it can be caught
    try:
        raise pyrepg.NotSupportedError('a generic database error')
    except pyrepg.NotSupportedError as error:
        pass

    return