472,331 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

Pyodbc and minimock with doctest


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

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 ?
Oct 31 '08 #1
0 1486

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Alan G Isaac | last post by:
> python doctest.py -v Running doctest.__doc__ Trying: .remove(42) Expecting: Traceback (most recent call last): File "<stdin>", line 1, in ?...
by: Michele Simionato | last post by:
Some time ago I hacked a custom solution to run doctests on text files containing documentation. The solution involved this kind of game: ...
by: king kikapu | last post by:
Hi to all, can anyone give me a jump-start about how to call Stored Procedures from PyODBC ?? I want to execute a very simple testing Stored...
by: Joe Salmeri | last post by:
I have found a data corruption problem with pyodbc. OS = Windows XP SP2 DB = Microsoft Access XP PROBLEM: When selecting columns from a...
by: Joe Salmeri | last post by:
I believe this bug is also related to the other problem I just reported. OS = Windows XP SP2 DB = Microsoft Access XP PROBLEM: When you use...
by: Rajendran | last post by:
Hi all, I've installed pyodbc module to access my database (MS Access). I've setup a User level DSN to the database.mdb file. When I run my...
by: Bzyczek | last post by:
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with...
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite...
by: Matthew Wilson | last post by:
I'm curious if anyone has ever tried using nosetests along with minimock. I'm trying to get the two to play nice and not making progress. I...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.