提交 3f9f9cfa authored 作者: AlexLamb's avatar AlexLamb

Updated unit test so that it passes flake8

上级 b045f9c4
import unittest import unittest
from theano.tests import unittest_tools as utt
import theano import theano
import theano.tensor as T import theano.tensor as T
import sys import sys
class dictionary_output_checker(unittest.TestCase):
class dictionary_output_checker(unittest.TestCase):
def test_output_list(self): def test_output_list(self):
x = T.scalar() x = T.scalar()
f = theano.function([x], outputs = [x, x*2, x*3]) f = theano.function([x], outputs=[x, x*2, x*3])
outputs = f(10.0) outputs = f(10.0)
...@@ -22,10 +18,9 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -22,10 +18,9 @@ class dictionary_output_checker(unittest.TestCase):
assert outputs[2] == 30.0 assert outputs[2] == 30.0
def test_output_dictionary(self): def test_output_dictionary(self):
x = T.scalar() x = T.scalar()
f = theano.function([x], outputs={'a': x, 'c': x*2,
f = theano.function([x], outputs = {'a' : x, 'c' : x*2, 'b' : x*3, '1' : x*4}) 'b': x*3, '1': x*4})
outputs = f(10.0) outputs = f(10.0)
...@@ -38,11 +33,11 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -38,11 +33,11 @@ class dictionary_output_checker(unittest.TestCase):
x = T.scalar('x') x = T.scalar('x')
y = T.scalar('y') y = T.scalar('y')
f = theano.function([x,y], outputs = {'a' : x + y, 'b' : x * y}) f = theano.function([x, y], outputs={'a': x + y, 'b': x * y})
assert f(2,4) == {'a' : 6, 'b' : 8} assert f(2, 4) == {'a': 6, 'b': 8}
assert f(2, y = 4) == f(2,4) assert f(2, y=4) == f(2, 4)
assert f(x = 2, y = 4) == f(2,4) assert f(x=2, y=4) == f(2, 4)
def test_output_order(self): def test_output_order(self):
x = T.scalar('x') x = T.scalar('x')
...@@ -51,7 +46,8 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -51,7 +46,8 @@ class dictionary_output_checker(unittest.TestCase):
e1 = T.scalar('1') e1 = T.scalar('1')
e2 = T.scalar('2') e2 = T.scalar('2')
f = theano.function([x,y,z,e1,e2], outputs = {'x':x,'y':y,'z':z,'1':e1,'2':e2}) f = theano.function([x, y, z, e1, e2], outputs={'x': x, 'y': y, 'z': z,
'1': e1, '2': e2})
assert '1' in str(f.outputs[0]) assert '1' in str(f.outputs[0])
assert '2' in str(f.outputs[1]) assert '2' in str(f.outputs[1])
...@@ -66,7 +62,7 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -66,7 +62,7 @@ class dictionary_output_checker(unittest.TestCase):
a = x + y a = x + y
b = x * y b = x * y
f = theano.function([x,y], outputs = {'a' : a, 'b' : b}) f = theano.function([x, y], outputs={'a': a, 'b': b})
a = T.scalar('a') a = T.scalar('a')
b = T.scalar('b') b = T.scalar('b')
...@@ -74,18 +70,18 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -74,18 +70,18 @@ class dictionary_output_checker(unittest.TestCase):
l = a + b l = a + b
r = a * b r = a * b
g = theano.function([a,b], outputs = [l,r]) g = theano.function([a, b], outputs=[l, r])
result = g(**f(5,7)) result = g(**f(5, 7))
assert result[0] == 47.0 assert result[0] == 47.0
assert result[1] == 420.0 assert result[1] == 420.0
def test_output_list(self): def test_output_list_still_works(self):
x = T.scalar('x') x = T.scalar('x')
f = theano.function([x], outputs = [x * 3, x * 2, x * 4, x]) f = theano.function([x], outputs=[x * 3, x * 2, x * 4, x])
result = f(5.0) result = f(5.0)
...@@ -99,7 +95,8 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -99,7 +95,8 @@ class dictionary_output_checker(unittest.TestCase):
print sys.stderr, "Running debug mode with dict" print sys.stderr, "Running debug mode with dict"
f = theano.function([x], outputs = {'1' : x, '2' : 2 * x, '3' : 3 * x}, mode = "DEBUG_MODE") f = theano.function([x], outputs={'1': x, '2': 2 * x,
'3': 3 * x}, mode="DEBUG_MODE")
result = f(3.0) result = f(3.0)
...@@ -111,12 +108,10 @@ class dictionary_output_checker(unittest.TestCase): ...@@ -111,12 +108,10 @@ class dictionary_output_checker(unittest.TestCase):
x = T.scalar('x') x = T.scalar('x')
f = theano.function([x], outputs = [x, 2 * x, 3 * x]) f = theano.function([x], outputs=[x, 2 * x, 3 * x])
result = f(5.0) result = f(5.0)
assert result[0] == 5.0 assert result[0] == 5.0
assert result[1] == 10.0 assert result[1] == 10.0
assert result[2] == 15.0 assert result[2] == 15.0
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论