changeset 64:37fd244f015e

More/improved tests
author David Grundberg <individ@acc.umu.se>
date Mon, 08 Jun 2009 21:00:10 +0200
parents f379cb14c4d4 (current diff) 590cd2fedcc1 (diff)
children 11cff59bc932 c19f5826b843
files
diffstat 2 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jun 08 15:35:08 2009 +0200
+++ b/ChangeLog	Mon Jun 08 21:00:10 2009 +0200
@@ -1,3 +1,8 @@
+2009-06-08  David Grundberg  <individ@acc.umu.se>
+
+	* test/test.py: New tests for pytave.globals and pytave.locals.
+	(testsetget, testexception): Call fail() instead of print.
+
 2009-06-03  Jaroslav Hajek  <highegg@gmail.com>
 
 	* pytave.cc (delvar): New function.
--- a/test/test.py	Mon Jun 08 15:35:08 2009 +0200
+++ b/test/test.py	Mon Jun 08 21:00:10 2009 +0200
@@ -124,20 +124,20 @@
 	try:
 		variables[name] = value
 		if name not in variables:
-			print "FAIL: set/get: ", name,": Should exist, not there."
+			fail("set/get: %s: Should exist, not there." % name)
 		result, = pytave.feval(1, "isequal", value, variables[name])
 		if not result:
-			print "FAIL: set/get: ", name," -> ",value," results diverged"
+			fail("set/get: %s -> %s: results diverged" % (name, value))
 	except Exception, e:
-		print "FAIL: set/get: ", name, ":", e
+		fail("set/get: %s" % name, e)
 
 def testexception(exception, func):
 	try:
 		func()
-		print "FAIL: ", name
+		fail("Expecting %s but nothing was raised." % repr(exception))
 	except Exception, e:
 		if not isinstance(e, exception):
-			print "FAIL:", name, ":", e
+			fail("Expecting %s but got %s instead" % (repr(exception), repr(e)), e)
 
 def testlocalscope(x):
 
@@ -163,7 +163,6 @@
     except Exception, e:
 	fail("testlocalscope: %s" % (x,), e)
 
-
 testmatrix(alimit_int32)
 testmatrix(alimit_int16)
 testmatrix(alimit_int8)
@@ -252,7 +251,7 @@
 testparseerror(1, "endfunction")
 testevalexpect(1, "2 + 2", (4,))
 testevalexpect(1, "{2}", ([2],))
-testevalexpect(2, "struct('foo', 2)", ({'foo': 2},))
+testevalexpect(1, "struct('foo', 2)", ({'foo': 2},))
 
 testsetget(pytave.locals, "xxx", [1,2,3])
 testsetget(pytave.globals, "xxx", [1,2,3])
@@ -279,6 +278,30 @@
 
 testlocalscope(5)
 
+testexception(KeyError, lambda: pytave.locals["localvariable"])
+pytave.locals["localvariable"] = 1
+if "localvariable" in pytave.globals:
+	fail("Local variable in globals")
+del pytave.locals["localvariable"]
+if "localvariable" in pytave.locals:
+	fail("Could not clear local variable")
+testexception(KeyError, lambda: pytave.locals["localvariable"])
+def func():
+	del pytave.locals["localvariable"]
+testexception(KeyError, lambda: func())
+
+testexception(KeyError, lambda: pytave.globals["globalvariable"])
+pytave.globals["globalvariable"] = 1
+if "globalvariable" in pytave.locals:
+	fail("Global variable in locals")
+del pytave.globals["globalvariable"]
+if "globalvariable" in pytave.globals:
+	fail("Could not clear global variable")
+testexception(KeyError, lambda: pytave.globals["globalvariable"])
+def func():
+	del pytave.globals["globalvariable"]
+testexception(KeyError, lambda: func())
+
 # Emacs
 #	Local Variables:
 #	fill-column:70