Skip to content

Commit 1b8388f

Browse files
committed
test(avro): share the decoder list through a fixture
Add tests/avro/conftest.py with AVAILABLE_DECODERS and a decoder_class fixture, so tests run against every decoder without repeating the list. The fixture avoids importing the constant across test modules: CI runs pytest on tests/avro/test_decoder.py on its own, where the repository root is not on sys.path and 'from tests.avro.conftest import ...' fails with ModuleNotFoundError.
1 parent 71d6eff commit 1b8388f

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎tests/avro/conftest.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
from __future__ import annotations
18+
19+
from collections.abc import Callable
20+
21+
import pytest
22+
23+
from pyiceberg.avro.decoder import BinaryDecoder, StreamingBinaryDecoder
24+
from pyiceberg.avro.decoder_fast import CythonBinaryDecoder
25+
26+
AVAILABLE_DECODERS = [StreamingBinaryDecoder, CythonBinaryDecoder]
27+
28+
29+
@pytest.fixture(params=AVAILABLE_DECODERS)
30+
def decoder_class(request: pytest.FixtureRequest) -> Callable[[bytes], BinaryDecoder]:
31+
"""Run a test against every available decoder implementation."""
32+
return request.param

‎tests/avro/test_resolver.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import pytest
2222
from pydantic import Field
2323

24-
from pyiceberg.avro.decoder import BinaryDecoder, StreamingBinaryDecoder
25-
from pyiceberg.avro.decoder_fast import CythonBinaryDecoder
24+
from pyiceberg.avro.decoder import BinaryDecoder
2625
from pyiceberg.avro.file import AvroFile
2726
from pyiceberg.avro.reader import (
2827
DecimalReader,
@@ -423,7 +422,6 @@ def test_writer_missing_optional_in_read_schema() -> None:
423422
assert actual == expected
424423

425424

426-
@pytest.mark.parametrize("decoder_class", [StreamingBinaryDecoder, CythonBinaryDecoder])
427425
def test_enum_reader_skip_advances_the_decoder(decoder_class: Callable[[bytes], BinaryDecoder]) -> None:
428426
"""Skipping an enum field must consume its bytes, or the next field is read from them."""
429427
# Two ints, zigzag encoded: the enum's ordinal 1, then the next field's value 12.
@@ -435,7 +433,6 @@ def test_enum_reader_skip_advances_the_decoder(decoder_class: Callable[[bytes],
435433
assert IntegerReader().read(decoder) == 12
436434

437435

438-
@pytest.mark.parametrize("decoder_class", [StreamingBinaryDecoder, CythonBinaryDecoder])
439436
def test_enum_reader_skip_matches_read(decoder_class: Callable[[bytes], BinaryDecoder]) -> None:
440437
"""Reading and skipping must leave the decoder at the same position."""
441438
encoded = b"\x02\x18"

0 commit comments

Comments
 (0)