from magento.configurable_requirements import (
    extract_configurable_requirements,
    is_valid_attribute_code,
    resolve_magento_axis_code,
    sanitize_attribute_code_list,
)


def test_resolve_magento_axis_code_maps_variation_depth():
    assert resolve_magento_axis_code("variation_depth_in") == "depth"
    assert resolve_magento_axis_code("height") == "height"


def test_invalid_attribute_codes_rejected():
    assert resolve_magento_axis_code("nan") is None
    assert resolve_magento_axis_code("variation_option_label") is None
    assert is_valid_attribute_code(float("nan")) is False


def test_extract_configurable_requirements_maps_axes_and_labels():
    rows = [
        {
            "configurable_attributes": "variation_depth_in,variation_option_label,nan",
            "configurable_variations": (
                "sku=C1,variation_depth_in=0.75,height=120|"
                "sku=C2,variation_depth_in=0.75,height=96"
            ),
        }
    ]
    codes, _, labels = extract_configurable_requirements(rows)
    assert codes == {"depth", "height"}
    assert labels["depth"] == {"0.75"}
    assert labels["height"] == {"120", "96"}


def test_sanitize_attribute_code_list():
    assert sanitize_attribute_code_list(["nan", "variation_width_in", "width", "variation_option_label"]) == [
        "width"
    ]
