提交 9d8d5f48 authored 作者: Frederic Bastien's avatar Frederic Bastien
...@@ -17,14 +17,13 @@ class T_test_module(unittest.TestCase): ...@@ -17,14 +17,13 @@ class T_test_module(unittest.TestCase):
B = Blah(0.0) B = Blah(0.0)
b = B.make(mode='FAST_RUN') b = B.make(mode='FAST_RUN')
b.step(1.0) b.step(1.0)
print b.stepsize
assert b.stepsize == 0.0 assert b.stepsize == 0.0
def test_no_shared_members(self): def test_no_shared_members(self):
"""Test that a Result cannot become a Member of two connected Modules """Test that a Result cannot become a Member of two connected Modules
FRED: What is the purpose of this test? Why we should not be able to do it? Fred: What is the purpose of this test? Why we should not be able to do it? I think we should be able to share member.
Right now it seem to work when it should not. Right now it seem to work when it should not.
""" """
x=T.dscalar() x=T.dscalar()
y=Member(T.dscalar()) y=Member(T.dscalar())
...@@ -35,8 +34,13 @@ class T_test_module(unittest.TestCase): ...@@ -35,8 +34,13 @@ class T_test_module(unittest.TestCase):
m1.y=y m1.y=y
m2.y=y m2.y=y
m2.m1=m1 m2.m1=m1
m2.make() inst1=m1.make()
m1.make() inst2=m2.make()
# inst1.y=1
# inst2.y=2
print inst1
print inst2
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED1" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED1"
def test_members_in_list_tuple_or_dict(self): def test_members_in_list_tuple_or_dict(self):
...@@ -45,6 +49,7 @@ class T_test_module(unittest.TestCase): ...@@ -45,6 +49,7 @@ class T_test_module(unittest.TestCase):
Fred: toplevel attribute? do you mean as a toplevel member? m1.x=x work as m1.lx=[x]? Fred: toplevel attribute? do you mean as a toplevel member? m1.x=x work as m1.lx=[x]?
Fred: why list,tuple of result are casted to member? Fred: why list,tuple of result are casted to member?
Fred: why no wrapper for dict? Should I add one? Fred: why no wrapper for dict? Should I add one?
Fred: why we don't promote a Result to a member, but we do it for lsit and tuple of results?
""" """
def local_test(x,y): def local_test(x,y):
...@@ -75,8 +80,66 @@ class T_test_module(unittest.TestCase): ...@@ -75,8 +80,66 @@ class T_test_module(unittest.TestCase):
def test_method_in_list_or_dict(self): def test_method_in_list_or_dict(self):
"""Test that a Method which is only included via a list or dictionary is still treated as if it """Test that a Method which is only included via a list or dictionary is still treated as if it
were a toplevel attribute""" were a toplevel attribute
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" Fred: why do we promote a list or tuple of fct of result to a Method?
Fred: why we don't do this of direct fct of results or dict?
"""
def local_test(x,y):
m1=Module()
m1.lx=[x]#cast Result to Member
m1.ly=[y]#cast Result to Member
m1.dx={"x":x}
m1.dy={"y":y}
m1.tx=(x,)#cast Result to Member
m1.ty=(y,)#cast Result to Member
m1.x=x
m1.y=y
z=x*2
// print type(z)
m1.z=z
m1.lz=[z]
m1.dz={"z":z}
m1.tz=(z,)
m1.zz1=Method(x,x*2)
m1.zz2=m1.zz1
m1.lzz1=[Method(x,x*2)]
m1.lzz2=[m1.zz1]
m1.dzz1={"z":m1.zz1}
m1.dzz2={"z":Method(x,x*2)}
m1.tzz1=(Method(x,x*2),)
m1.tzz2=(m1.zz1,)
inst=m1.make()
assert inst.lx
assert inst.ly
assert inst.tx
assert inst.ty
inst.y # we don't assert just make the look up as with T.dscalar it return None
# but it don't return None for value and constant
self.assertRaises(AttributeError, inst.__getattr__, "x")
self.assertRaises(AttributeError, inst.__getattr__, "dx")
self.assertRaises(AttributeError, inst.__getattr__, "dy")
self.assertRaises(AttributeError, inst.__getattr__, "z")
self.assertRaises(AttributeError, inst.__getattr__, "lz")
self.assertRaises(AttributeError, inst.__getattr__, "dz")
self.assertRaises(AttributeError, inst.__getattr__, "tz")
self.assertRaises(AttributeError, inst.__getattr__, "dzz1")
self.assertRaises(AttributeError, inst.__getattr__, "dzz2")
print m1
print inst
assert inst.zz1(2)
assert inst.zz2(2)
assert inst.lzz1[0](2)
assert inst.lzz2[0](2)
assert inst.tzz1[0](2)
assert inst.tzz2[0](2)
local_test(T.dscalar(),Member(T.dscalar()))
local_test(T.value(1),Member(T.value(2)))
local_test(T.constant(1),Member(T.constant(2)))
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED3"
def test_shared_members(self): def test_shared_members(self):
"""Test that under a variety of tricky conditions, the shared-ness of Results and Members """Test that under a variety of tricky conditions, the shared-ness of Results and Members
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论