home *** CD-ROM | disk | FTP | other *** search
- #### test command line version
- import os, sys, time
-
- print "Sorry, this test program is out of date compared to the code."
- print "It has been disabled."
-
- sys.exit(1)
-
- print "This test takes a long time and requires Internet access!"
- print "You have three seconds to hit control-C and quit."
-
- pyfilename = os.path.join(os.path.split(sys.argv[0])[0], "..", "pyppm.py")
-
- def ppm(command):
- return "%s %s %s" %(sys.executable, pyfilename, command)
-
- def ppmEcho(command):
- return "echo %s | %s %s" %(command , sys.executable, pyfilename)
-
- def assertSuccess(command):
- rc = os.system(ppm(command))
- #assert rc==0, "Ran: %s, expected: %d, got: %d" % (command, 0, rc)
-
- def assertFails(command):
- rc = os.system(ppm(command))
- #assert rc!=0, "Ran: %s, expected: %s, got: %d" % (command, "non-zero", rc)
-
- def Contains(command, string):
- info = os.popen(ppm(command)).read()
- return info.find(string)!=-1
-
- def ContainsWithEcho(command, string):
- info = os.popen(ppmEcho(command)).read()
- return info.find(string)!=-1
-
- def assertContains(command, string):
- assert Contains(command, string), \
- "Ran %s, expected output to contain %s, got, %s" \
- %( command, string, os.popen(ppm(command)).read())
- def assertContainsWithEcho(command, string):
- assert ContainsWithEcho(command, string), \
- "Ran %s through echo, expected output to contain %s, got, %s" \
- %( command, string, os.popen(ppmEcho(command)).read())
-
- # use this one when the command has no side-effects
- def assertBothContains(command, string):
- assertContains(command, string)
- assertContainsWithEcho(command, string)
-
- assertSuccess("help help")
- assertBothContains("help help", "search")
- assertBothContains("help help", "query")
- assertBothContains("help foobar", "No help on")
-
- def testModule(packname, modname=None):
- if not modname:
- modname = packname
- if Contains("query", packname):
- assertSuccess("verify --upgrade --force %s"% packname)
- else:
- assertSuccess("install %s" % packname)
-
- assertBothContains("query", packname)
- assertBothContains("query %s" % packname, packname)
- assertFails("install %s" % packname)
- fullpath = os.popen('python -c "import %s; print %s.__file__"'%
- (modname, modname)).read().strip()
- assert os.path.exists(fullpath), (fullpath, modname)
- return fullpath
-
- #testModule("tk", "Tkinter")
- #turtledata = os.popen('python -c "import turtle; print turtle.demo()"').read()
- #assert turtledata.find("None")>=0
-
- numfullpath = testModule("Numeric")
- numpath, _ = os.path.split(numfullpath)
- mandelpath = os.path.join(numpath, "Demo", "mandelbrot.py")
- mandeldata = os.popen('python ' + mandelpath).read()
- print mandeldata
- assert mandeldata.find("BBBBBBBBBBBBB")!=-1
-
-
- print "All tests succeeded"
-
- import PPM
-