inside doctest works not unittest

This commit is contained in:
lafrite 2014-12-02 11:06:29 +01:00
parent cccfb9e90b
commit cecf06e082

View File

@ -3,27 +3,26 @@
from .generic import flatten_list, isNumber from .generic import flatten_list, isNumber
import types
class Operator(object): class Operator(str):
"""The operator class, is a string (representation of the operator) with its arity""" """The operator class, is a string (representation of the operator) with its arity"""
def __init__(self, operator = "", priority = 0, actions = ("",""), txt = "", tex = "", arity = 2): def __new__(cls, operator = "", priority = 0, actions = ("",""), txt = "", tex = "", arity = 2):
""" Create an Operator """ """ Create an Operator """
self.name = operator #def __new__(cls, operator, arity = 2):
self.arity = arity op = str.__new__(cls, operator)
op.name = operator
op.arity = arity
op.priority = priority
op.actions = actions
op.txt = txt
op.tex = tex
op.isOperator = 1
# TODO: Add self.visibility |sam. nov. 8 17:00:08 CET 2014 # TODO: Add self.visibility |sam. nov. 8 17:00:08 CET 2014
return op
self.priority = priority
self.actions = actions
self.txt = txt
self.tex = tex
self.isselferator = 1
def __str__(self):
return self.name
def __call__(self, *args): def __call__(self, *args):
""" Calling this operator performs the rigth calculus """ """ Calling this operator performs the rigth calculus """
@ -183,15 +182,14 @@ def operatorize(fun):
ans = fun(self, *args) ans = fun(self, *args)
op = Operator(ans["operator"]) op = Operator(ans["operator"])
print("type(op)", type(op))
for (attr, value) in ans.items(): for (attr, value) in ans.items():
if hasattr(value, '__call__'): if hasattr(value, '__call__'):
print("value :", type(value)) #callback = lambda *args, **kwrds: value(op, *args, **kwrds)
print("value :", str(value)) #setattr(op, attr, callback)
callback = lambda *args, **kwrds: value(op, *args, **kwrds) setattr(op, attr, types.MethodType(value, op))
setattr(op, attr, callback)
else: else:
setattr(op, attr, value) setattr(op, attr, value)
return op return op
return mod_fun return mod_fun
@ -257,7 +255,7 @@ class op(object):
caract = { caract = {
"operator" : "-", \ "operator" : "-", \
"priority" : 2, \ "priority" : 2, \
"arity" : 2, \ "arity" : 1, \
"action" : "__neg__",\ "action" : "__neg__",\
"txt" : "- {op1}",\ "txt" : "- {op1}",\
"tex" : "- {op1}",\ "tex" : "- {op1}",\
@ -273,10 +271,6 @@ class op(object):
# * can not be display in some cases # * can not be display in some cases
def _render(self, link, *args): def _render(self, link, *args):
#print("self->", str(self))
#print("link ->", str(link))
#print("*args ->", str(args))
replacement = {"op"+str(i+1): ' '.join(self.add_parenthesis(op)) for (i,op) in enumerate(args)} replacement = {"op"+str(i+1): ' '.join(self.add_parenthesis(op)) for (i,op) in enumerate(args)}
if not self.visibility or args[1][0] == "(" or \ if not self.visibility or args[1][0] == "(" or \