import pytest
import etl.epc_clean.epc_attributes.attribute_utils as attribute_utils


def test_extract_thermal_transmittance():
    description = "average thermal transmittance 2.3 w/m-¦k"
    assert attribute_utils.extract_thermal_transmittance({}, description) == (
        {'thermal_transmittance': 2.3, 'thermal_transmittance_unit': 'w/m-¦k'}, '')


def test_clean_description():
    test_cases = [
        ("this:is;a*test", "this is a test"),
        ("hello@world", "hello world"),
        ("what?!?", "what "),
        ("hello(world)", "hello world "),
        ("", ""),
        (":;*@?!", " "),
        ("no special chars", "no special chars")
    ]

    for input_str, expected_output in test_cases:
        assert attribute_utils.clean_description(input_str) == expected_output


# Test for normal operation
def test_process_part_normal_operation():
    result = {'has_glazing': False, 'has_glazed': False, 'has_glaze': False}
    part = 'high performance glazing'
    attr_list = ['glazing', 'glazed', 'glaze']
    prefix = 'has_'
    expected_result = {'has_glazing': True, 'has_glazed': False, 'has_glaze': False}

    assert attribute_utils.process_part(result, part, attr_list, prefix) == expected_result


# Test for TypeError exceptions
def test_process_part_type_errors():
    result = 'not a dictionary'
    part = 'high performance glazing'
    attr_list = ['glazing', 'glazed', 'glaze']
    prefix = 'has_'
    with pytest.raises(TypeError):
        attribute_utils.process_part(result, part, attr_list, prefix)


# Test for ValueError exceptions
def test_process_part_value_errors():
    result = {}
    part = 'high performance glazing'
    attr_list = ['glazing', 'glazed', 'glaze']
    prefix = 'has_'
    with pytest.raises(ValueError):
        attribute_utils.process_part(result, part, attr_list, prefix)

# Test for no attribute matches found - we don't raise this error any more
# def test_process_part_no_matches():
#     result = {'has_glazing': False, 'has_glazed': False, 'has_glaze': False}
#     part = 'high performance coating'
#     attr_list = ['glazing', 'glazed', 'glaze']
#     prefix = 'has_'
#     with pytest.raises(ValueError):
#         attribute_utils.process_part(result, part, attr_list, prefix)
