doctest + sqlobject (TDD)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • petr.jakes.tpc@gmail.com

    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(S QLObject):
    pass

    if __name__ == "__main__":
    import doctest
    doctest.testfil e("displeje_pok us.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\dis pleje_pokus.txt ", line 13, in displeje_pokus. txt
    Failed example:
    import displeje_pokus
    Exception raised:
    Traceback (most recent call last):
    File "C:\Python25\li b\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\dis pleje_pokus.py" , line 41, in <module>
    class TextyDispleje(s qlobject.SQLObj ect):
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\decl arative.py", line 121, in __new__
    cls.__classinit __(cls, new_attrs)
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\main .py", line 803, in __classinit__
    classregistry.r egistry(cls.sql meta.registry). addClass(cls)
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\clas sregistry.py", line 91, in addClass
    '__file__', '(unknown)')))
    ValueError: class TextyDispleje is already in the registry (other
    class is <class '__main__.Texty Displeje'>, from the module __main__ in
    Z:\automat\disp leje_pokus.py; attempted new class is <class
    'displeje_pokus .TextyDispleje' >, from the module displeje_pokus in Z:
    \automat\disple je_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.
  • Peter Otten

    #2
    Re: doctest + sqlobject (TDD)

    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(S QLObject):
    pass
    >
    if __name__ == "__main__":
    import doctest
    doctest.testfil e("displeje_pok us.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\dis pleje_pokus.txt ", line 13, in displeje_pokus. txt
    Failed example:
    import displeje_pokus
    Exception raised:
    Traceback (most recent call last):
    File "C:\Python25\li b\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\dis pleje_pokus.py" , line 41, in <module>
    class TextyDispleje(s qlobject.SQLObj ect):
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\decl arative.py", line 121, in __new__
    cls.__classinit __(cls, new_attrs)
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\main .py", line 803, in __classinit__
    classregistry.r egistry(cls.sql meta.registry). addClass(cls)
    File "c:\python25\li b\site-packages\SQLObj ect-0.9.2-py2.5.egg
    \sqlobject\clas sregistry.py", line 91, in addClass
    '__file__', '(unknown)')))
    ValueError: class TextyDispleje is already in the registry (other
    class is <class '__main__.Texty Displeje'>, from the module __main__ in
    Z:\automat\disp leje_pokus.py; attempted new class is <class
    'displeje_pokus .TextyDispleje' >, from the module displeje_pokus in Z:
    \automat\disple je_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__.TextyD ispleje 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(S QLObject):
    pass

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

    Peter

    Comment

    • petr.jakes.tpc@gmail.com

      #3
      Re: doctest + sqlobject (TDD)

      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(S QLObject):
      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=disp leje_pokus.myFu nction

      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

      Comment

      • Peter Otten

        #4
        Re: doctest + sqlobject (TDD)

        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=disp leje_pokus.myFu nction
        >
        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.testfil e() 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".

        Comment

        • petr.jakes.tpc@gmail.com

          #5
          Re: doctest + sqlobject (TDD)

          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.testfil e() 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".

          Comment

          Working...