From a7e543a15f0db890a80777251719db2d05001ba2 Mon Sep 17 00:00:00 2001 From: Chamikara Jayalath Date: Wed, 2 Nov 2016 14:33:09 -0700 Subject: [PATCH] Fixes two bugs in avroio_test 'test_corrupted_file'. (1) Updates test to perform corruption properly (setting 'A' and 'B'). (2) Removes an invalid usage of bytearray(). --- sdks/python/apache_beam/io/avroio_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdks/python/apache_beam/io/avroio_test.py b/sdks/python/apache_beam/io/avroio_test.py index f72c3f3addbc..9e356ca3aaa5 100644 --- a/sdks/python/apache_beam/io/avroio_test.py +++ b/sdks/python/apache_beam/io/avroio_test.py @@ -228,15 +228,16 @@ def test_dynamic_work_rebalancing_exhaustive(self): def test_corrupted_file(self): file_name = self._write_data() with open(file_name, 'rb') as f: - data = bytearray(f.read()) + data = f.read() # Corrupt the last character of the file which is also the last character of # the last sync_marker. + last_char_index = len(data) - 1 + corrupted_data = data[:last_char_index] + corrupted_data += 'A' if data[last_char_index] == 'B' else 'B' with tempfile.NamedTemporaryFile( delete=False, prefix=tempfile.template) as f: - last_char_index = len(data) - 1 - data[last_char_index] = 'A' if data[last_char_index] == 'B' else 'A' - f.write(data) + f.write(corrupted_data) corrupted_file_name = f.name source = AvroSource(corrupted_file_name)