Repository: incubator-beam Updated Branches: refs/heads/python-sdk 7e870613f -> 9d2acc98e
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(). Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/a7e543a1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/a7e543a1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/a7e543a1 Branch: refs/heads/python-sdk Commit: a7e543a15f0db890a80777251719db2d05001ba2 Parents: 7e87061 Author: Chamikara Jayalath <[email protected]> Authored: Wed Nov 2 14:33:09 2016 -0700 Committer: Chamikara Jayalath <[email protected]> Committed: Wed Nov 2 14:44:12 2016 -0700 ---------------------------------------------------------------------- sdks/python/apache_beam/io/avroio_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a7e543a1/sdks/python/apache_beam/io/avroio_test.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/io/avroio_test.py b/sdks/python/apache_beam/io/avroio_test.py index f72c3f3..9e356ca 100644 --- a/sdks/python/apache_beam/io/avroio_test.py +++ b/sdks/python/apache_beam/io/avroio_test.py @@ -228,15 +228,16 @@ class TestAvro(unittest.TestCase): 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)
