提交 5b4a0d08 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Apply pyupgrade to tests.gof

上级 30cfad4b
...@@ -78,7 +78,7 @@ class X: ...@@ -78,7 +78,7 @@ class X:
return str(leaf.type) return str(leaf.type)
def node_formatter(self, node, argstrings): def node_formatter(self, node, argstrings):
return "%s(%s)" % (node.op, ", ".join(argstrings)) return "{}({})".format(node.op, ", ".join(argstrings))
def str(self, inputs, outputs): def str(self, inputs, outputs):
return as_string( return as_string(
......
import numpy as np import numpy as np
import pytest import pytest
from six import string_types
import theano import theano
import theano.gof.op as op import theano.gof.op as op
...@@ -34,7 +33,7 @@ class MyType(Type): ...@@ -34,7 +33,7 @@ class MyType(Type):
def filter(self, x, strict=False, allow_downcast=None): def filter(self, x, strict=False, allow_downcast=None):
# Dummy filter: we want this type to represent strings that # Dummy filter: we want this type to represent strings that
# start with `self.thingy`. # start with `self.thingy`.
if not isinstance(x, string_types): if not isinstance(x, str):
raise TypeError("Invalid type") raise TypeError("Invalid type")
if not x.startswith(self.thingy): if not x.startswith(self.thingy):
raise ValueError("Invalid value") raise ValueError("Invalid value")
...@@ -89,10 +88,10 @@ class StructOp(Op): ...@@ -89,10 +88,10 @@ class StructOp(Op):
return Apply(self, [i], [scalar.uint64()]) return Apply(self, [i], [scalar.uint64()])
def c_support_code_struct(self, node, name): def c_support_code_struct(self, node, name):
return "npy_uint64 counter%s;" % (name,) return "npy_uint64 counter{};".format(name)
def c_init_code_struct(self, node, name, sub): def c_init_code_struct(self, node, name, sub):
return "counter%s = 0;" % (name,) return "counter{} = 0;".format(name)
def c_code(self, node, name, input_names, outputs_names, sub): def c_code(self, node, name, input_names, outputs_names, sub):
return """ return """
......
...@@ -548,7 +548,7 @@ class TestMergeOptimizer: ...@@ -548,7 +548,7 @@ class TestMergeOptimizer:
assert len(no_input_ops) == 2, fg.apply_nodes assert len(no_input_ops) == 2, fg.apply_nodes
class TestEquilibrium(object): class TestEquilibrium:
def test_1(self): def test_1(self):
x, y, z = map(MyVariable, "xyz") x, y, z = map(MyVariable, "xyz")
e = op3(op4(x, y)) e = op3(op4(x, y))
......
...@@ -102,7 +102,7 @@ class QuadraticCOpFunc(COp): ...@@ -102,7 +102,7 @@ class QuadraticCOpFunc(COp):
params_type = ParamsType(a=tensor_type_0d, b=scalar_type, c=generic_type) params_type = ParamsType(a=tensor_type_0d, b=scalar_type, c=generic_type)
def __init__(self, a, b, c): def __init__(self, a, b, c):
super(QuadraticCOpFunc, self).__init__( super().__init__(
"c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)" "c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)"
) )
self.a = a self.a = a
......
...@@ -45,11 +45,11 @@ def test_reverse_dict(): ...@@ -45,11 +45,11 @@ def test_reverse_dict():
def test__toposort(): def test__toposort():
edges = { edges = {
1: set((4, 6, 7)), 1: {4, 6, 7},
2: set((4, 6, 7)), 2: {4, 6, 7},
3: set((5, 7)), 3: {5, 7},
4: set((6, 7)), 4: {6, 7},
5: set((7,)), 5: {7},
} }
order = _toposort(edges) order = _toposort(edges)
assert not any( assert not any(
......
...@@ -100,7 +100,9 @@ def test_speed(): ...@@ -100,7 +100,9 @@ def test_speed():
t_b = t3 - t2 t_b = t3 - t2
print( print(
"%s takes %f s/Kop" % ("numpy", (1000 * (t_b - t_a) / (steps_b - steps_a))) "{} takes {:f} s/Kop".format(
"numpy", (1000 * (t_b - t_a) / (steps_b - steps_a))
)
) )
def time_linker(name, linker): def time_linker(name, linker):
...@@ -127,7 +129,11 @@ def test_speed(): ...@@ -127,7 +129,11 @@ def test_speed():
t_a = t1 - t0 t_a = t1 - t0
t_b = t3 - t2 t_b = t3 - t2
print("%s takes %f s/Kop" % (name, (1000 * (t_b - t_a) / (steps_b - steps_a)))) print(
"{} takes {:f} s/Kop".format(
name, (1000 * (t_b - t_a) / (steps_b - steps_a))
)
)
time_linker("c|py", OpWiseCLinker) time_linker("c|py", OpWiseCLinker)
time_linker("vmLinker", vm.VM_Linker) time_linker("vmLinker", vm.VM_Linker)
...@@ -170,7 +176,11 @@ def test_speed_lazy(): ...@@ -170,7 +176,11 @@ def test_speed_lazy():
t_a = t1 - t0 t_a = t1 - t0
t_b = t3 - t2 t_b = t3 - t2
print("%s takes %f s/Kop" % (name, (1000 * (t_b - t_a) / (steps_b - steps_a)))) print(
"{} takes {:f} s/Kop".format(
name, (1000 * (t_b - t_a) / (steps_b - steps_a))
)
)
time_linker("vmLinker", vm.VM_Linker) time_linker("vmLinker", vm.VM_Linker)
time_linker("vmLinker_nogc", lambda: vm.VM_Linker(allow_gc=False)) time_linker("vmLinker_nogc", lambda: vm.VM_Linker(allow_gc=False))
...@@ -425,7 +435,7 @@ def test_reallocation(): ...@@ -425,7 +435,7 @@ def test_reallocation():
return [False, None] return [False, None]
assert check_storage(storage_map)[0] assert check_storage(storage_map)[0]
assert len(set(id(v) for v in storage_map.values())) < len(storage_map) assert len({id(v) for v in storage_map.values()}) < len(storage_map)
@pytest.mark.skipif( @pytest.mark.skipif(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论