Re-enable TestNamedTensor.test_big_tensor_repr (#29407)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29407

Fixes https://github.com/pytorch/pytorch/issues/27753.

The bug was that random tensors print subtly differently. This causes
the "names=" tag to appear in slightly different places; sometimes it is
on the same line as the data, sometimes it is on different lines.

For this test, we wanted to know the following:
- printing a big named tensor's repr doesn't crash
- a big named tensor's repr shows the names

This PR changes the test to check those two things.

Test Plan: - run existing tests

Differential Revision: D18428657

Pulled By: zou3519

fbshipit-source-id: 6bcf247ffba010520878a175e766a496028f87d9
This commit is contained in:
Richard Zou 2019-11-11 13:30:00 -08:00 committed by Facebook Github Bot
parent b3b8f522e8
commit cedca377bd

View File

@ -275,12 +275,11 @@ class TestNamedTensor(TestCase):
with self.assertRaisesRegex(RuntimeError, "NYI"): with self.assertRaisesRegex(RuntimeError, "NYI"):
ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(named_tensor) ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(named_tensor)
@unittest.skip("Issue 27753") def test_big_tensor_repr_has_names(self):
def test_big_tensor_repr(self):
def check_repr(named_tensor): def check_repr(named_tensor):
unnamed_tensor = named_tensor.rename(None) unnamed_tensor = named_tensor.rename(None)
expected = "{}, names={})".format(repr(unnamed_tensor)[:-1], named_tensor.names) names_tag = 'names={}'.format(named_tensor.names)
self.assertEqual(repr(named_tensor), expected) self.assertIn(names_tag, repr(named_tensor))
check_repr(torch.randn(128, 3, 64, 64, names=('N', 'C', 'H', 'W'))) check_repr(torch.randn(128, 3, 64, 64, names=('N', 'C', 'H', 'W')))