473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Pyodbc and minimock with doctest

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

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

Similar topics

2
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 ? ValueError: list.remove(x): x not in list ok...
2
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: tester=doctest.Tester(globs={},verbose=1)...
1
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 Procedure on an Sql Server database. I started...
3
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 table that are of type Memo the value returned is...
2
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 + (or &) to concatenation columns together and...
3
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 python code in the command prompt it is retrieving the...
6
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 encoding definition: # -*- coding: utf-8 -*- I...
0
bartonc
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 to the mix. The this update is due to my...
1
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 also wonder if I'm using minimock incorrectly. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.