expecttest
expecttest copied to clipboard
AssertionError: Failed to substitute string
Thanks for a slick little utility, which I'll certainly make use of in my own projects!
In updating a pytorch unit test, I ran into an error that told me to report it here. (This isn't blocking me, it's a tiny edit, so no rush.)
FAIL: test_functional_call_sequential_params_and_buffers (__main__.FuncTorchHigherOrderOpTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/rec/git/pytorch/torch/testing/_internal/common_utils.py", line 2979, in wrapper
method(*args, **kwargs)
File "/home/rec/.conda/envs/pytorch-dev/lib/python3.8/contextlib.py", line 75, in inner
return func(*args, **kwds)
File "test/dynamo/test_higher_order_ops.py", line 3825, in test_functional_call_sequential_params_and_buffers
self.assertExpectedInline(
File "/home/rec/git/pytorch/torch/testing/_internal/common_utils.py", line 2925, in assertExpectedInline
return super().assertExpectedInline(actual if isinstance(actual, str) else str(actual), expect, skip + 1)
File "/home/rec/.conda/envs/pytorch-dev/lib/python3.8/site-packages/expecttest/__init__.py", line 351, in assertExpectedInline
assert_expected_inline(
File "/home/rec/.conda/envs/pytorch-dev/lib/python3.8/site-packages/expecttest/__init__.py", line 292, in assert_expected_inline
assert old != new, (
AssertionError: Failed to substitute string at test/dynamo/test_higher_order_ops.py:3825; did you use triple quotes? If this is unexpected, please file a bug report at https://github.com/ezyang/expecttest/issues/new with the contents of the source file near test/dynamo/test_higher_order_ops.py:3825
The code in question is below, starting at test/dynamo/test_higher_order_ops.py:3890
I thought it might be the """\
combo, but getting rid of the backslash didn't change the error.
actual = normalize_gm(wrapped_gm.print_readable(print_output=False))
if torch._dynamo.config.inline_inbuilt_nn_modules:
expected = """\
class GraphModule(torch.nn.Module):
def forward(self, L_params_l1_weight_: "f32[1, 1]", L_params_l1_bias_: "f32[1]", L_buffers_buffer_: "f32[1]", L_inputs_: "f32[1, 1]"):
l_params_l1_weight_ = L_params_l1_weight_
l_params_l1_bias_ = L_params_l1_bias_
l_buffers_buffer_ = L_buffers_buffer_
l_inputs_ = L_inputs_
linear: "f32[1, 1]" = torch._C._nn.linear(l_inputs_, l_params_l1_weight_, l_params_l1_bias_); l_inputs_ = l_params_l1_weight_ = l_params_l1_bias_ = None
add: "f32[1, 1]" = linear + l_buffers_buffer_; linear = l_buffers_buffer_ = None
return (add,)
"""
# We found Windows/Linux have some empty line difference, empty_line_normalizer will help fix it.
self.assertExpectedInline(
empty_line_normalizer(actual),
empty_line_normalizer(normalize_gm(expected)),
)
else:
self.assertExpectedInline(
actual,
"""\
class GraphModule(torch.nn.Module):
def forward(self, L_x_: "f32[1, 1]"):
l_x_ = L_x_
l__self___l1: "f32[1, 1]" = self.L__self___l1(l_x_); l_x_ = None
l__self___buffer: "f32[1]" = self.L__self___buffer
add: "f32[1, 1]" = l__self___l1 + l__self___buffer; l__self___l1 = l__self___buffer = None
return (add,)
""",
)