Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src-python/amazon/ionbenchmark/ion_load_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load(self, fp):

def dumps(self, obj):
ion.c_ext = self._c_ext
return ion.dumps(obj, binary=self._binary)
return ion.dumps(obj, binary=self._binary, sequence_as_stream=True)

def dump(self, obj, fp):
ion.c_ext = self._c_ext
Expand Down
21 changes: 21 additions & 0 deletions tests/test_benchmark_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import cbor2
import pytest

from amazon.ion import simpleion
from amazon.ion.equivalence import ion_equals
Expand Down Expand Up @@ -139,6 +140,26 @@ def test_write_generate_multiple_top_level_cbor_values():
assert obj_count == load_count


@pytest.mark.parametrize('format_option', ['ion_text', 'ion_binary'])
@pytest.mark.parametrize('values', [[], [1], [1, {'name': 'value'}], [[1, 2]]])
def test_buffer_write_preserves_top_level_values(format_option, values, tmp_path, monkeypatch):
monkeypatch.setattr(simpleion, 'c_ext', False)
input_file = tmp_path / 'input.ion'
with input_file.open('wb') as fp:
simpleion.dump(values, fp, binary=True, sequence_as_stream=True)
params = {'command': 'write', 'format': format_option, 'input_file': str(input_file),
'py_c_extension': False}
buffer_fun = _create_test_fun(BenchmarkSpec({**params, 'io_type': 'buffer'}))
output_file = tmp_path / 'output.ion'
_create_test_fun(BenchmarkSpec({**params, 'io_type': 'file'}), custom_file=str(output_file))()
with output_file.open('rb') as fp:
file_values = simpleion.load(fp, single_value=False)
assert ion_equals(file_values, values)
# Benchmark functions are called repeatedly with the same input stream.
for _ in range(2):
assert ion_equals(simpleion.loads(buffer_fun(), single_value=False), file_values)


def test_get_input_file_size():
real_size = _minimal_spec.get_input_file_size()
exp_size = Path(join(_generate_test_path("sample_spec"), _minimal_params['input_file'])).stat().st_size
Expand Down