mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Fix protobuf test comparison by parsing proto instead of raw strings (#162644)
The tests were comparing raw exported strings for protobuf comparison, which is not backward/forward compatible with different versions of protobuf. This PR parses the strings into protobuf and compares the protobufs directly, similar to what we did in assertImageProto. Our test failed because we used a different version of protobuf, which output 44100.0 instead of 44100, which resulted in an error. However, they are equal, but only different in the exported strings. Pull Request resolved: https://github.com/pytorch/pytorch/pull/162644 Approved by: https://github.com/justinchuby, https://github.com/Skylion007
This commit is contained in:
@ -82,13 +82,14 @@ class BaseTestCase(TestCase):
|
||||
if os.path.exists(temp_dir):
|
||||
shutil.rmtree(temp_dir)
|
||||
|
||||
def assertProto(self, str_to_compare):
|
||||
def assertProto(self, actual_proto):
|
||||
if expecttest.ACCEPT:
|
||||
write_proto(str_to_compare, self)
|
||||
write_proto(actual_proto, self)
|
||||
return True
|
||||
expected = read_expected_content(self)
|
||||
str_to_compare = str(str_to_compare)
|
||||
self.assertEqual(remove_whitespace(str_to_compare), remove_whitespace(expected))
|
||||
expected_str = read_expected_content(self)
|
||||
expected_proto = Summary()
|
||||
text_format.Parse(expected_str, expected_proto)
|
||||
self.assertEqual(actual_proto, expected_proto)
|
||||
|
||||
def assertImageProto(self, actual_proto):
|
||||
if expecttest.ACCEPT:
|
||||
|
Reference in New Issue
Block a user