import adtf_file
import os
import logging

import pytest

adtf_runtime_dir = os.environ["adtf_runtime_DIR"]
logger = logging.getLogger(__name__)


def test_python_processor():
    adtf_file.load_plugin(os.path.dirname(
        os.path.abspath(adtf_file.__file__)) + "/../adtf_file_python_processor/python_processor.adtffileplugin")
    demultiplexer = adtf_file.create_demultiplexer(
        adtf_runtime_dir + "/examples/demo_adtfdat_files/example_file.adtfdat")

    script = os.path.dirname(os.path.abspath(__file__)) + r"/../examples/adtf_file_python_processor/demo_exporter.py"
    logger.info(script)
    demultiplexer.add_processor("NESTED_STRUCT", "", "python", "",
                                {"script": script})

    progress = 0

    def progress_callback(progress_float):
        nonlocal progress
        progress = progress_float
        print(f"Progress: {progress_float * 100:.2f}%")
        return True

    demultiplexer.process(progress_callback)
    assert (progress != 0)
