Running DocTest on Strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • notanotheridiot

    Running DocTest on Strings

    Hi,
    I have two strings - a docstring containing doctests and a code string
    containing code to be tested with those doctests. I've been trying for
    a day now to run the test without concatenating the two strings,
    adding:

    import doctest
    doctest.testmod

    to the bottom, writing it all to a file and executing it using popen().

    There must be some way of doing this without writing to a temporary
    file, any ideas?

    thanks in advance,

    johannes Woolard

  • Paddy

    #2
    Re: Running DocTest on Strings


    notanotheridiot wrote:[color=blue]
    > Hi,
    > I have two strings - a docstring containing doctests and a code string
    > containing code to be tested with those doctests. I've been trying for
    > a day now to run the test without concatenating the two strings,
    > adding:
    >
    > import doctest
    > doctest.testmod
    >
    > to the bottom, writing it all to a file and executing it using popen().
    >
    > There must be some way of doing this without writing to a temporary
    > file, any ideas?
    >
    > thanks in advance,
    >
    > johannes Woolard[/color]
    Create the concatenated string then exec it?

    - Pad.

    Comment

    • André

      #3
      Re: Running DocTest on Strings


      Paddy wrote:[color=blue]
      > notanotheridiot wrote:[color=green]
      > > Hi,
      > > I have two strings - a docstring containing doctests and a code string
      > > containing code to be tested with those doctests. I've been trying for
      > > a day now to run the test without concatenating the two strings,
      > > adding:
      > >
      > > import doctest
      > > doctest.testmod
      > >
      > > to the bottom, writing it all to a file and executing it using popen().
      > >
      > > There must be some way of doing this without writing to a temporary
      > > file, any ideas?
      > >
      > > thanks in advance,
      > >
      > > johannes Woolard[/color]
      > Create the concatenated string then exec it?[/color]

      I know from experience that this approach does not work. When you do
      that, the entire module from which it is run turns out to be scanned
      for doctests - not only the string being executed by exec. However, I
      understand that Johannes found a solution.

      André
      [color=blue]
      >
      > - Pad.[/color]

      Comment

      • notanotheridiot

        #4
        Re: Running DocTest on Strings


        André wrote:[color=blue]
        > Paddy wrote:[color=green]
        > > notanotheridiot wrote:[color=darkred]
        > > > Hi,
        > > > I have two strings - a docstring containing doctests and a code string
        > > > containing code to be tested with those doctests. I've been trying for
        > > > a day now to run the test without concatenating the two strings,
        > > > adding:
        > > >
        > > > import doctest
        > > > doctest.testmod
        > > >
        > > > to the bottom, writing it all to a file and executing it using popen().
        > > >
        > > > There must be some way of doing this without writing to a temporary
        > > > file, any ideas?
        > > >
        > > > thanks in advance,
        > > >
        > > > johannes Woolard[/color]
        > > Create the concatenated string then exec it?[/color]
        >
        > I know from experience that this approach does not work. When you do
        > that, the entire module from which it is run turns out to be scanned
        > for doctests - not only the string being executed by exec. However, I
        > understand that Johannes found a solution.
        >
        > André
        >[color=green]
        > >
        > > - Pad.[/color][/color]

        Got it, I've blogged about it here:
        My last post mentioned the problems I was having with doctests, luckily I managed to solve them - but only after about 5 hours of frustrated...

        Basically the trick is to pass the docstring ino the exec environment
        as a variable and use the advanced doctest api to get a doctest.

        Johannes

        Comment

        Working...