changeset 1:10b59d5be10e

Added doctests
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 11 Nov 2008 11:02:11 +0100
parents 3107bd7ca4af
children b8efe2734cc6
files __init__.py doctests.py pretty_print.py secret_ifs.py
diffstat 3 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doctests.py	Tue Nov 11 11:02:11 2008 +0100
@@ -0,0 +1,7 @@
+from doctest import testfile
+
+for i in ["secret_ifs.py",
+          "pretty_print.py"]:
+    testfile(i)
+
+
--- a/pretty_print.py	Tue Nov 11 10:12:17 2008 +0100
+++ b/pretty_print.py	Tue Nov 11 11:02:11 2008 +0100
@@ -99,6 +99,12 @@
     """Returns a string representation of the expression.
     *prec* is the precedence of the surrounding of the expression,
     and determines if parenthesis are neccesary.
+    >>> from ast import *
+    >>> from pretty_print import *
+    >>> expr_string(BinOp(op=Mult(), left=BinOp(op=Add(), left=Num(1),
+    ... right=Num(4)), right=Num(2)))
+    '(1 + 4) * 2'
+
     """
     if hasattr(exp, "op"):
         my_precedence = op_precedence(exp.op)
--- a/secret_ifs.py	Tue Nov 11 10:12:17 2008 +0100
+++ b/secret_ifs.py	Tue Nov 11 11:02:11 2008 +0100
@@ -5,7 +5,7 @@
 """
 
 import ast
-from util import error
+from static.util import error
 
 
 class Assignments(ast.NodeVisitor):
@@ -41,12 +41,15 @@
     """
     >>> from ast import *
     >>> from pretty_print import *
+    >>> from secret_ifs import TransformIfs
     >>> prog = parse("def f(x):\n\tif(x):\n\t\ta=1\n\telse:\n\t\ta=2")
-    >>> TransfromIfs().visit(prog)
+    >>> trans = TransformIfs()
+    >>> prog = trans.visit(prog)
     >>> pprint(prog)
     def f(x):
         cond0 = x
         a = cond0 * 1 + (1 - cond0) * 2
+
     """
     cond_counter = 0
 
@@ -55,8 +58,6 @@
         only_assignments(node.body)
         assigned_then = get_assignments(node.body)
         assigned_else = get_assignments(node.orelse)
-        print assigned_then
-        print assigned_else
         all_assigned = set(assigned_then.keys() + assigned_else.keys())
         r = []
         condname = ast.Name(id="cond%d" % self.cond_counter)