Commit a1fb2fb0 authored by BOHMRR's avatar BOHMRR
Browse files

added docstring to custom fixtures

some fixtures now fail with pytest.exit()
adjusted default names of reference binaries
parent c8c38d0d
Loading
Loading
Loading
Loading
+61 −17
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ def log_dbg_msg(message):

@pytest.fixture(scope="session", autouse=True)
def rootdir(request):
    """
    Return root directory for tests.
    """
    return str(request.config.rootdir)


@@ -114,11 +117,20 @@ def pytest_addoption(parser):

@pytest.fixture(scope="session", autouse=True)
def update_ref(request):
    """
    Return indication whether references shall be updated.
    0: Only DUT processing, no reference generation.
    1: Only reference generation (unconditionally), no DUT processing.
    2: DUT processing, references are generated when not present.
    """
    return int(request.config.getoption("--update_ref"))


@pytest.fixture(scope="session")
def dut_encoder_path(request) -> Path:
def dut_encoder_path(request) -> str:
    """
    Return path of DUT encoder binary.
    """
    if request.config.option.dut_encoder_path:
        return request.config.option.dut_encoder_path

@@ -134,7 +146,8 @@ def dut_encoder_path(request) -> Path:

    path = str(path.resolve())

    assert os.path.isfile(path)
    if not os.path.isfile(path):
        pytest.exit(f"\nDUT encoder binary {path} not found!\n!")

    return path

@@ -221,6 +234,9 @@ class EncoderFrontend:

@pytest.fixture(scope="function")
def dut_encoder_frontend(dut_encoder_path) -> EncoderFrontend:
    """
    Return a :class:`conftest.EncoderFrontend` instance as DUT for the test session.
    """
    encoder = EncoderFrontend(dut_encoder_path, "DUT")
    yield encoder

@@ -229,33 +245,40 @@ def dut_encoder_frontend(dut_encoder_path) -> EncoderFrontend:


@pytest.fixture(scope="session")
def ref_encoder_path(request) -> Path:
def ref_encoder_path(request) -> str:
    """
    Return path of REF encoder binary.
    """
    if request.config.option.ref_encoder_path:
        return request.config.option.ref_encoder_path

    if request.config.option.update_ref == "0":
        return None

    # assume default encoder when update_ref is selected, but no ref_encoder_path is specified
    # assume specifically named encoder when update_ref is selected, but no ref_encoder_path is specified
    here = Path(__file__).parent.resolve()
    system = platform.system()

    if system == "Windows":
        path = here.joinpath("../IVAS_cod.exe")
        path = here.joinpath("../IVAS_cod_ref.exe")
    elif system in ["Darwin", "Linux"]:
        path = here.joinpath("../IVAS_cod")
        path = here.joinpath("../IVAS_cod_ref")
    else:
        raise ValueError(f'Wrong system "{system}"!')

    path = str(path.resolve())

    assert os.path.isfile(path)
    if not os.path.isfile(path):
        pytest.exit(f"\nREF encoder binary {path} not found!\n!")

    return path


@pytest.fixture(scope="session")
def dut_decoder_path(request) -> Path:
def dut_decoder_path(request) -> str:
    """
    Return path of DUT decoder binary.
    """
    if request.config.option.dut_decoder_path:
        return request.config.option.dut_decoder_path

@@ -271,7 +294,8 @@ def dut_decoder_path(request) -> Path:

    path = str(path.resolve())

    assert os.path.isfile(path)
    if not os.path.isfile(path):
        pytest.exit(f"\nDUT decoder binary {path} not found!\n!")

    return path

@@ -344,6 +368,9 @@ class DecoderFrontend:

@pytest.fixture(scope="function")
def dut_decoder_frontend(dut_decoder_path) -> DecoderFrontend:
    """
    Return a :class:`conftest.DecoderFrontend` instance as DUT for the test session.
    """
    decoder = DecoderFrontend(dut_decoder_path, "DUT")
    yield decoder

@@ -352,33 +379,40 @@ def dut_decoder_frontend(dut_decoder_path) -> DecoderFrontend:


@pytest.fixture(scope="session")
def ref_decoder_path(request) -> Path:
def ref_decoder_path(request) -> str:
    """
    Return path of REF decoder binary.
    """
    if request.config.option.ref_decoder_path:
        return request.config.option.ref_decoder_path

    if request.config.option.update_ref == "0":
        return None

    # assume default decoder when update_ref is selected, but no ref_decoder_path is specified
    # assume specifically named decoder when update_ref is selected, but no ref_decoder_path is specified
    here = Path(__file__).parent.resolve()
    system = platform.system()

    if system == "Windows":
        path = here.joinpath("../IVAS_dec.exe")
        path = here.joinpath("../IVAS_dec_ref.exe")
    elif system in ["Darwin", "Linux"]:
        path = here.joinpath("../IVAS_dec")
        path = here.joinpath("../IVAS_dec_ref")
    else:
        raise ValueError(f'Wrong system "{system}"!')

    path = str(path.resolve())

    assert os.path.isfile(path)
    if not os.path.isfile(path):
        pytest.exit(f"\nREF decoder binary {path} not found!\n!")

    return path


@pytest.fixture(scope="session")
def test_vector_path(request) -> Path:
def test_vector_path(request) -> str:
    """
    Return base directory of test vector files.
    """
    if request.config.option.test_vector_path:
        return request.config.option.test_vector_path

@@ -392,7 +426,10 @@ def test_vector_path(request) -> Path:


@pytest.fixture(scope="session")
def reference_path(request) -> Path:
def reference_path(request) -> str:
    """
    Return base directory of reference files.
    """
    if request.config.option.reference_path:
        return request.config.option.reference_path

@@ -402,11 +439,18 @@ def reference_path(request) -> Path:

    path = str(path.resolve())

    if request.config.option.update_ref == "0":
        if not os.path.isdir(path):
            pytest.exit(f"\nREF path {path} not found!\nPlease generate the references, first!\n!")

    return path


@pytest.fixture(scope="session")
def dut_base_path(request) -> Path:
def dut_base_path(request) -> str:
    """
    Return base data directory for dut files.
    """
    if request.config.option.dut_base_path:
        return request.config.option.dut_base_path