import os
import tempfile
from steps.common import Case


def before_all(context):
    context.image_template_path = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__),
            "..",
            "test_images"
        )
    )
    print("Image template path: {}".format(context.image_template_path))
    context.test_images = {
        "1200.jpg": os.path.join(context.image_template_path, "test_image_1200.jpg"),
        "1200_16bit_RGB.png": os.path.join(context.image_template_path, "test_image_1200_16bit_rgb.png"),
        "thumb_normal": os.path.join(context.image_template_path, "test_image_thumb_normal.png"),
        "thumb_large": os.path.join(context.image_template_path, "test_image_thumb_large.png"),
        "thumb_x-large": os.path.join(context.image_template_path, "test_image_thumb_x-large.png"),
        "thumb_xx-large": os.path.join(context.image_template_path, "test_image_thumb_xx-large.png"),
    }
    context.bin = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__),
            "..",
            "..",
            "target",
            "debug",
            "allmytoes"
        )
    )
    assert os.path.isfile(context.bin), "{} does not exist".format(context.bin)


def before_scenario(context, scenario):
    wd = tempfile.mkdtemp()
    context.working_dir = wd
    context.env = {
        "RUST_LOG": "trace",
        "HOME": wd,
    }
    context.case = Case(working_dir=wd, test_images=context.test_images)


def after_scenario(context, scenario):
    pass
    # shutil.rmtree(context.working_dir)
