import pytest
from etl.epc_clean.tests.test_data.test_floor_attributes_cases import clean_floor_cases
from etl.epc_clean.epc_attributes.FloorAttributes import FloorAttributes


class TestCleanFloor:

    def test_init(self):
        # Test initialization with a valid description
        valid_description = 'Solid, limited insulation (assumed)'
        floor_attr = FloorAttributes(valid_description)
        assert floor_attr.description == valid_description.lower()

        # Test initialization with a description that contains none of the keywords
        with pytest.raises(ValueError):
            FloorAttributes('description without keywords')

    @pytest.mark.parametrize(
        "test_case",
        clean_floor_cases
    )
    def test_process_floor(self, test_case):
        expected_result = test_case.copy()
        del expected_result["original_description"]
        result = FloorAttributes(test_case['original_description']).process()
        # Ensure the output ordering is correct
        assert sorted(result.items()) == sorted(expected_result.items())

    def test_empty_str_description(self):
        assert FloorAttributes("").process() == {
            'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_assumed': False,
            'is_to_unheated_space': False, 'is_to_external_air': False, 'is_suspended': False, 'is_solid': False,
            'another_property_below': False, 'insulation_thickness': 'none', 'no_data': True
        }

    def test_invalid_description(self):
        # Test that invalid descriptions raise a ValueError
        invalid_descriptions = [
            "invalid description",
            "description with no known floor data_types or thermal transmittance",
        ]

        for description in invalid_descriptions:
            with pytest.raises(ValueError):
                FloorAttributes(description).process()

    def test_process_with_invalid_description(self):
        # Test that processing an invalid description raises a ValueError
        invalid_description = 'description without keywords'
        with pytest.raises(ValueError):
            FloorAttributes(invalid_description)

    def test_known_errors(self):
        error_description = "Conservatory"
        obj = FloorAttributes(error_description)
        assert obj.nodata
