Pyodbc and minimock with doctest

Discussion in 'Python' started by dj, Oct 31, 2008.

  1. dj

    dj Guest

    Hello,

    I have just started working with minimock in doctest.
    I want to create a mock pyodbc object which returns a string value
    when the method execute is called.

    Here is my doctest:

    >>> from minimock import Mock
    >>> import pyodbc


    >>> def database_response()

    .... ServerName = 'test_server'
    .... DbName = 'test_database'
    .... User = 'test_user'
    .... Pass ='test_pass'
    .... connstring ='DRIVER{SQL Server};SERVER=%s;DATABASE=%s;UID=
    %s;PWD=%s;' % (ServerName,
    .... DbName, User, Pass)
    .... cnx = pyodbc.connect(connstring)
    .... cur = cnx.cursor()
    .... name = cur.execute("select user_id from user")
    .... print 'name:%s' % name

    >>> pyodbc = Mock('pyodbc')
    >>> pyodbc.connect.mock_returns = Mock('pyodbc')
    >>> pyodbc.cursor.mock_returns = Mock('pyodbc')
    >>> pyodbc.execute = Mock('pyodbc.execute', returns=True)
    >>> pyodbc.execute.returns = 'Return this string.'
    >>> pyodbc.execute.mock_returns = Mock('pyodbc.execute')


    >>> database_response() #doctest: +ELLIPSIS

    ....


    Here is the output from doctest:
    *****************************************************************************
    File ".\pyodbc_test.txt", line 35, in pyodbc_test.txt
    Failed example:
    database_response() #doctest: +ELLIPSIS
    Expected nothing
    Got:

    Called pyodbc.connect({DRIVER{SQLServer};
    SERVER=test_server;DATABASE=test_database;UID=test_user;PWD=test_pass;')
    Called pyodbc.cursor()
    Called pyodbc.execute('select user_id from users')
    name: None
    *******************************************************************************************
    The last line of the output, name : Name, should read, name: Return
    this string.
    Clearly I am not assigning the string correctly, but I can't figure
    out what I am
    doing wrong. Any ideas ?
    dj, Oct 31, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. timw.googlepost

    installing pyodbc

    timw.googlepost, Apr 11, 2006, in forum: Python
    Replies:
    0
    Views:
    340
    timw.googlepost
    Apr 11, 2006
  2. timw.googlepost

    installing pyodbc

    timw.googlepost, Apr 11, 2006, in forum: Python
    Replies:
    0
    Views:
    286
    timw.googlepost
    Apr 11, 2006
  3. timw.googlepost

    installing pyodbc

    timw.googlepost, Apr 11, 2006, in forum: Python
    Replies:
    0
    Views:
    288
    timw.googlepost
    Apr 11, 2006
  4. Matthew Wilson
    Replies:
    1
    Views:
    390
    John J. Lee
    Oct 22, 2007
  5. MacRules
    Replies:
    9
    Views:
    803
    Dennis Lee Bieber
    Sep 5, 2009
Loading...

Share This Page