472,782 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 1437
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.