Loading ...
Sorry, an error occurred while loading the content.
 

doctests under Windows - fix

Expand Messages
  • David Harris
    The Python readme file recommends running the doctests (step 7) after installing the data and code files. Under Windows XP with Python 2.3.3, the given command
    Message 1 of 1 , May 1, 2005
      The Python readme file recommends running the doctests (step 7) after
      installing the data and code files. Under Windows XP with Python 2.3.3,
      the given command (python doctest.py -v *.py) yields:

      Traceback (most recent call last):
      File: "doctests.py", line 44, in ?
      modules = [__import__(name.replace('.py',''))
      ImportError: No module named *

      To old DOS programmers, the reason is obvious - Windows does not
      perform wildcard expansion on command line arguments.

      The following change corrects the problem for Windows and should
      continue to operate properly under other operating systems. Note: this
      implementation does not need to check for the platform AND it corrects
      a defect in the original code that ran doctests on doctests.py twice.

      In doctests.py, replace:

      import sys
      modules = [__import__(name.replace('.py',''))
      for name in sys.argv if name != "-v"]
      run_tests(modules, ("-v" in sys.argv))

      with:

      import sys
      import glob
      modules = [__import__(name[0].replace('.py',''))
      for name in [glob.glob(arg)
      for arg in sys.argv[1:] if arg != "-v"]]
      if modules:
      run_tests(modules, ("-v" in sys.argv))

      Hope this helps someone.
      Dave Harris



      __________________________________
      Do you Yahoo!?
      Yahoo! Small Business - Try our new resources site!
      http://smallbusiness.yahoo.com/resources/
    Your message has been successfully submitted and would be delivered to recipients shortly.