提交 53ca7d6f authored 作者: Frederic Bastien's avatar Frederic Bastien

-refactored the test_module to be a class of unittest so that we can use assertRaise

-started writing missing test.
上级 55c5a737
import unittest
from theano.compile.module import * from theano.compile.module import *
import theano.tensor as T import theano.tensor as T
import sys import sys
def test_whats_up_with_submembers(): class T_test_module(unittest.TestCase):
def test_whats_up_with_submembers(self):
class Blah(FancyModule): class Blah(FancyModule):
def __init__(self, stepsize): def __init__(self, stepsize):
super(Blah, self).__init__() super(Blah, self).__init__(self)
self.stepsize = Member(T.value(stepsize)) self.stepsize = Member(T.value(stepsize))
x = T.dscalar() x = T.dscalar()
...@@ -18,22 +21,54 @@ def test_whats_up_with_submembers(): ...@@ -18,22 +21,54 @@ def test_whats_up_with_submembers():
assert b.stepsize == 0.0 assert b.stepsize == 0.0
def test_no_shared_members(): 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?
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" Right now it seem to work when it should not.
"""
def test_members_in_list_or_dict(): x=T.dscalar()
y=Member(T.dscalar())
m1=Module()
m2=Module()
m1.x=x
m2.x=x
m1.y=y
m2.y=y
m2.m1=m1
m2.make()
m1.make()
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED1"
def test_members_in_list_or_dict(self):
"""Test that a Member which is only included via a list or dictionary is still treated as if it """Test that a Member 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: toplevel attribute? toplevel member?
"""
def test_method_in_list_or_dict():
x=T.dscalar()
y=Member(T.dscalar())
m1=Module()
m1.lx=[x]
m1.ly=[y]
m1.dx={"x":x}
m1.dy={"y":y}
m1.x=x
m1.y=y
inst=m1.make()
print m1
print inst
assert inst.lx
assert inst.ly
self.assertRaises(AttributeError, inst.__getattr__, x)
self.assertRaises(AttributeError, inst.__getattr__, y)#FRED why this raise an exception?
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED2"
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" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
def test_shared_members(): 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
is respected.""" is respected."""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
...@@ -41,7 +76,7 @@ def test_shared_members(): ...@@ -41,7 +76,7 @@ def test_shared_members():
#put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between #put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between
#a list and a submodule with a dictionary, etc... #a list and a submodule with a dictionary, etc...
def test_shared_members_N(): def test_shared_members_N(self):
"""Test that Members can be shared an arbitrary number of times between many submodules and """Test that Members can be shared an arbitrary number of times between many submodules and
internal data structures.""" internal data structures."""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
...@@ -49,7 +84,7 @@ def test_shared_members_N(): ...@@ -49,7 +84,7 @@ def test_shared_members_N():
#put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between #put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between
#a list and a submodule with a dictionary, etc... #a list and a submodule with a dictionary, etc...
def test_shared_method(): def test_shared_method(self):
"""Test that under a variety of tricky conditions, the shared-ness of Results and Methods """Test that under a variety of tricky conditions, the shared-ness of Results and Methods
is respected.""" is respected."""
...@@ -57,7 +92,7 @@ def test_shared_method(): ...@@ -57,7 +92,7 @@ def test_shared_method():
#put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between #put them in subModules, sub-sub-Modules, shared between a list and a dict, shared between
#a list and a submodule with a dictionary, etc... #a list and a submodule with a dictionary, etc...
def test_shared_method_N(): def test_shared_method_N(self):
"""Test that Methods can be shared an arbitrary number of times between many submodules and """Test that Methods can be shared an arbitrary number of times between many submodules and
internal data structures.""" internal data structures."""
...@@ -65,22 +100,22 @@ def test_shared_method_N(): ...@@ -65,22 +100,22 @@ def test_shared_method_N():
#a list and a submodule with a dictionary, etc... #a list and a submodule with a dictionary, etc...
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
def test_member_method_inputs(): def test_member_method_inputs(self):
"""Test that module Members can be named as Method inputs, in which case the function will """Test that module Members can be named as Method inputs, in which case the function will
*not* use the storage allocated for the Module's version of that Member.""" *not* use the storage allocated for the Module's version of that Member."""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
def test_member_input_flags(): def test_member_input_flags(self):
"""Test that we can manipulate the mutable, strict, etc. flags (see SymbolicInput) of """Test that we can manipulate the mutable, strict, etc. flags (see SymbolicInput) of
Method inputs""" Method inputs"""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
def test_member_output_flags(): def test_member_output_flags(self):
"""Test that we can manipulate the output flags (just 'borrow' I think, see SymbolicOutput) """Test that we can manipulate the output flags (just 'borrow' I think, see SymbolicOutput)
of Method outputs""" of Method outputs"""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
def test_sanity_check_mode(): def test_sanity_check_mode(self):
"""Test that Module.make() can take the same list of Modes that function can, so we can """Test that Module.make(self) can take the same list of Modes that function can, so we can
debug modules""" debug modules"""
print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED" print >> sys.stderr, "WARNING MODULE TEST NOT IMPLEMENTED"
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论