473,320 Members | 1,946 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,320 software developers and data experts.

doctest + sqlobject (TDD)

Hi,

inspired by the article written by Tarek Ziade in the February 07
issue of the "Linux +" magazine I am experimenting with the doctest
module.

I have two files, "displeje_pokus.py" and "displeje_pokus.txt" (you
can see the simplified contents of the files bellow).

When I run "python displeje_pokus.py" I am getting an error (see
below) which I am not able to eliminate.

thanks for your reply

Petr Jakes

======================
displeje_pokus.py
======================
from sqlobject import *
class TextyDispleje(SQLObject):
pass

if __name__ == "__main__":
import doctest
doctest.testfile("displeje_pokus.txt", verbose=True)

======================
displeje_pokus.txt
======================
>>import displeje_pokus


Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on VIT, Standard
>>Trying:
import displeje_pokus
Expecting nothing
************************************************** ********************
File "Z:\automat\displeje_pokus.txt", line 13, in displeje_pokus.txt
Failed example:
import displeje_pokus
Exception raised:
Traceback (most recent call last):
File "C:\Python25\lib\doctest.py", line 1212, in __run
compileflags, 1) in test.globs
File "<doctest displeje_pokus.txt[0]>", line 1, in <module>
import displeje_pokus
File "Z:\automat\displeje_pokus.py", line 41, in <module>
class TextyDispleje(sqlobject.SQLObject):
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\declarative.py", line 121, in __new__
cls.__classinit__(cls, new_attrs)
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\main.py", line 803, in __classinit__
classregistry.registry(cls.sqlmeta.registry).addCl ass(cls)
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\classregistry.py", line 91, in addClass
'__file__', '(unknown)')))
ValueError: class TextyDispleje is already in the registry (other
class is <class '__main__.TextyDispleje'>, from the module __main__ in
Z:\automat\displeje_pokus.py; attempted new class is <class
'displeje_pokus.TextyDispleje'>, from the module displeje_pokus in Z:
\automat\displeje_pokus.py)
************************************************** ********************
1 items had failures:
1 of 1 in displeje_pokus.txt
1 tests in 1 items.
0 passed and 1 failed.
***Test Failed*** 1 failures.
Dec 22 '07 #1
4 1465
petr.jakes.tpc wrote:
Hi,

inspired by the article written by Tarek Ziade in the February 07
issue of the "Linux +" magazine I am experimenting with the doctest
module.

I have two files, "displeje_pokus.py" and "displeje_pokus.txt" (you
can see the simplified contents of the files bellow).

When I run "python displeje_pokus.py" I am getting an error (see
below) which I am not able to eliminate.

thanks for your reply

Petr Jakes

======================
displeje_pokus.py
======================
from sqlobject import *
class TextyDispleje(SQLObject):
pass

if __name__ == "__main__":
import doctest
doctest.testfile("displeje_pokus.txt", verbose=True)

======================
displeje_pokus.txt
======================
>>>import displeje_pokus

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on VIT, Standard
>>>Trying:
import displeje_pokus
Expecting nothing
************************************************** ********************
File "Z:\automat\displeje_pokus.txt", line 13, in displeje_pokus.txt
Failed example:
import displeje_pokus
Exception raised:
Traceback (most recent call last):
File "C:\Python25\lib\doctest.py", line 1212, in __run
compileflags, 1) in test.globs
File "<doctest displeje_pokus.txt[0]>", line 1, in <module>
import displeje_pokus
File "Z:\automat\displeje_pokus.py", line 41, in <module>
class TextyDispleje(sqlobject.SQLObject):
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\declarative.py", line 121, in __new__
cls.__classinit__(cls, new_attrs)
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\main.py", line 803, in __classinit__
classregistry.registry(cls.sqlmeta.registry).addCl ass(cls)
File "c:\python25\lib\site-packages\SQLObject-0.9.2-py2.5.egg
\sqlobject\classregistry.py", line 91, in addClass
'__file__', '(unknown)')))
ValueError: class TextyDispleje is already in the registry (other
class is <class '__main__.TextyDispleje'>, from the module __main__ in
Z:\automat\displeje_pokus.py; attempted new class is <class
'displeje_pokus.TextyDispleje'>, from the module displeje_pokus in Z:
\automat\displeje_pokus.py)
************************************************** ********************
1 items had failures:
1 of 1 in displeje_pokus.txt
1 tests in 1 items.
0 passed and 1 failed.
***Test Failed*** 1 failures.
It seems that sqlobject does not allow for two SQLObject subclasses with
the same name:
>>from sqlobject import SQLObject
class A(SQLObject): pass
....
>>try:
.... class A(SQLObject): pass
.... except:
.... print "Oops!"
....
Oops!

In your scenario these are __main__.TextyDispleje and
displeje_pokus.TextyDispleye. While you could either alter the textfile to
>>import __main__ as displeje_pokus
or the module along the lines of

# not recommended!
from displeje_pokus import TextyDispleje
if __name__ == "__main__":
# doctest
else:
class TextyDispleje(SQLObject):
pass

the clean way to fix the problem is to use a separate script to invoke the
doctest.

Peter
Dec 22 '07 #2
On Dec 22, 7:05 pm, Peter Otten <__pete...@web.dewrote:
petr.jakes.tpc wrote:
While you could either alter the textfile to
>
>import __main__ as displeje_pokus

or the module along the lines of

# not recommended!
from displeje_pokus import TextyDispleje
if __name__ == "__main__":
# doctest
else:
class TextyDispleje(SQLObject):
pass

the clean way to fix the problem is to use a separate script to invoke the
doctest.

Peter
Peter,

thanks for your reply. I will try to live with the
>>import __main__ as displeje_pokus
in the text file.

Anyway, using this, it looks like I have to assign all functions/
methods to a local name like:

myFunction=displeje_pokus.myFunction

to avoid to write modul name (displeje_pokus) in front of the each
function/method calling.

Do you think there is a way how to protect the text file contents
against such a "assigning hell"?

Petr
Dec 22 '07 #3
petr.jakes.tpc wrote:
thanks for your reply. I will try to live with the
>>>import __main__ as displeje_pokus

in the text file.
Why?
Anyway, using this, it looks like I have to assign all functions/
methods to a local name like:

myFunction=displeje_pokus.myFunction

to avoid to write modul name (displeje_pokus) in front of the each
function/method calling.

Do you think there is a way how to protect the text file contents
against such a "assigning hell"?
This has nothing to do with your previous problem. Use

from __main__ import myFunction, myOtherFunction, ...

or

from __main__ import *

if you prefer "namespace pollution paradise"*.

Again, it would be better to move the doctest.testfile() call into a
separate script.

Peter

(*) which I'm tempted to write "namespace 'pollution' paradise" or
"namespace pollution 'paradise'", but don't, for fear of "quoting hell".
Dec 22 '07 #4
Thanks, it works.
And thanks for your comments which are worth to think about :)
Petr
This has nothing to do with your previous problem. Use

from __main__ import myFunction, myOtherFunction, ...

or

from __main__ import *

if you prefer "namespace pollution paradise"*.

Again, it would be better to move the doctest.testfile() call into a
separate script.

Peter

(*) which I'm tempted to write "namespace 'pollution' paradise" or
"namespace pollution 'paradise'", but don't, for fear of "quoting hell".
Dec 22 '07 #5

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...
1
by: Robin Munn | last post by:
I've been loving SQLObject. The ability to set up a database connection and then completely *forget* about it and just manipulate Python objects has been great. But I'm running into a problem, and...
1
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.7.2 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes,...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0b1 release of SQLObject. This is the first beta of the new branch. Taking into account that it is a result of rather large job the beta period will be...
3
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0b2 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0b3 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.7.4 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes,...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.10.0b1, the first beta release of a new SQLObject branch, 0.10. What is SQLObject ================= SQLObject is an object-relational mapper. Your...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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)...
0
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.