#! /usr/bin/env python
"""Rectangle compression workflow

Requires the following ``SConscript(..., exports={})``

* ``env`` - The SCons construction environment with the following required keys

  * ``test_source_abspath`` - String absolute path to the project's Python 3 test files
  * ``regression_alias`` - String for the alias collecting the regression workflow targets
"""

import pathlib

# Inherit the parent construction environment
Import("env")

# Set project-wide paths with os-agnostic path separators
test_source_abspath = env["test_source_abspath"]

# Set unit test workflow variables
build_directory = pathlib.Path(Dir(".").abspath)
workflow_name = build_directory.name

# Collect the target nodes to build a concise alias for all targets
workflow = []

# Unit test target
test_files = [test_source_abspath / "test_utilities.py"]
target = [f"{workflow_name}_results.xml"]
workflow.extend(
    env.Command(
        target=target,
        source=test_files,
        action="pytest -v --junitxml=${TARGETS[0]}",
    )
)
env.AlwaysBuild(workflow)
env.Alias(workflow_name, workflow)
env.Alias(env["regression_alias"], workflow)
