home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_PPM_testppm.py < prev    next >
Encoding:
Text File  |  2001-07-26  |  2.9 KB  |  86 lines

  1. #### test command line version
  2. import os, sys, time
  3.  
  4. print "Sorry, this test program is out of date compared to the code."
  5. print "It has been disabled."
  6.  
  7. sys.exit(1)
  8.  
  9. print "This test takes a long time and requires Internet access!"
  10. print "You have three seconds to hit control-C and quit."
  11.  
  12. pyfilename = os.path.join(os.path.split(sys.argv[0])[0], "..", "pyppm.py")
  13.  
  14. def ppm(command):
  15.     return "%s %s %s" %(sys.executable, pyfilename, command)
  16.  
  17. def ppmEcho(command):
  18.     return "echo %s | %s %s" %(command , sys.executable, pyfilename)
  19.  
  20. def assertSuccess(command):
  21.     rc = os.system(ppm(command))
  22.     #assert rc==0, "Ran: %s, expected: %d, got: %d" % (command, 0, rc)
  23.  
  24. def assertFails(command):
  25.     rc = os.system(ppm(command))
  26.     #assert rc!=0, "Ran: %s, expected: %s, got: %d" % (command, "non-zero", rc)
  27.  
  28. def Contains(command, string):
  29.     info = os.popen(ppm(command)).read()
  30.     return info.find(string)!=-1
  31.  
  32. def ContainsWithEcho(command, string):
  33.     info = os.popen(ppmEcho(command)).read()
  34.     return info.find(string)!=-1
  35.  
  36. def assertContains(command, string):
  37.     assert Contains(command, string), \
  38.            "Ran %s, expected output to contain %s, got, %s" \
  39.                %( command, string, os.popen(ppm(command)).read())
  40. def assertContainsWithEcho(command, string):
  41.     assert ContainsWithEcho(command, string), \
  42.            "Ran %s through echo, expected output to contain %s, got, %s" \
  43.                %( command, string, os.popen(ppmEcho(command)).read())
  44.  
  45. # use this one when the command has no side-effects
  46. def assertBothContains(command, string):
  47.     assertContains(command, string)
  48.     assertContainsWithEcho(command, string)
  49.  
  50. assertSuccess("help help")
  51. assertBothContains("help help", "search")
  52. assertBothContains("help help", "query")
  53. assertBothContains("help foobar", "No help on")
  54.  
  55. def testModule(packname, modname=None):
  56.     if not modname:
  57.         modname = packname
  58.     if Contains("query", packname):
  59.         assertSuccess("verify --upgrade --force %s"% packname)
  60.     else:
  61.         assertSuccess("install %s" % packname)
  62.  
  63.     assertBothContains("query", packname)
  64.     assertBothContains("query %s" % packname, packname)
  65.     assertFails("install %s" % packname)
  66.     fullpath = os.popen('python -c "import %s; print %s.__file__"'%
  67.                                            (modname, modname)).read().strip()
  68.     assert os.path.exists(fullpath), (fullpath, modname)
  69.     return fullpath
  70.  
  71. #testModule("tk", "Tkinter")
  72. #turtledata = os.popen('python -c "import turtle; print turtle.demo()"').read()
  73. #assert turtledata.find("None")>=0
  74.  
  75. numfullpath = testModule("Numeric")
  76. numpath, _ = os.path.split(numfullpath)
  77. mandelpath = os.path.join(numpath, "Demo", "mandelbrot.py")
  78. mandeldata = os.popen('python ' + mandelpath).read()
  79. print mandeldata
  80. assert mandeldata.find("BBBBBBBBBBBBB")!=-1
  81.  
  82.  
  83. print "All tests succeeded"
  84.  
  85. import PPM
  86.