def default_case(tmp_path) -> case_description.CaseDescription:
    """
    Minimum valid CaseDescription with pvt configured
    """
    tab_file = tmp_path / "dummy.tab"
    file_content = [
        'PVTTABLE LABEL = "PVT1",PHASE = THREE,',
        'PVTTABLE LABEL = "PVT2", PHASE = THREE,',
    ]
    tab_file.write_text("\n".join(file_content))
    return case_description.CaseDescription(
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT2",
            tables={"PVT1": f"{tab_file}"},
            correlations={
                "PVT2": case_description.PvtModelCorrelationDescription()
            },
            compositions={
                "PVT3": case_description.PvtModelCompositionalDescription()
            },
            table_parameters={
                "PVT4":
                case_description.PvtModelTableParametersDescription.
                create_empty()
            },
        ))
    omega=Scalar("dimensionless", 5, "-"),
    MW=Scalar("mass per mol", 6, "kg/mol"),
    Tb=Scalar("temperature", 7, "K"),
    Parachor=Scalar("dimensionless", 8, "-"),
    Cp_0=Scalar("dimensionless", 9, "-"),
    Cp_1=Scalar("dimensionless", 10, "-"),
    Cp_2=Scalar("dimensionless", 11, "-"),
    Cp_3=Scalar("dimensionless", 12, "-"),
    Cp_4=Scalar("dimensionless", 13, "-"),
)
LIGH_COMPONENT_DESCRIPTION_OVERWRITE_C3 = case_description.LightComponentDescription(
    name="C3", Pc=Scalar("pressure", 42, "Pa")
)
PVT_MODEL_CORRELATION_DEFINITION = case_description.PvtModelCorrelationDescription(
    oil_density_std=Scalar(42, "kg/m3"),
    gas_density_std=Scalar(2, "kg/m3"),
    rs_sat=Scalar(4, "sm3/sm3"),
    pvt_correlation_package=constants.CorrelationPackage.Lasater,
)
FLUID_DESCRIPTION = case_description.FluidDescription(
    composition=[COMPOSITION_DESCRIPTION_C1, COMPOSITION_DESCRIPTION_C2],
    fraction_pairs=[BIP_DESCRIPTION],
)
PVT_MODEL_COMPOSITIONAL_DEFINITION = case_description.PvtModelCompositionalDescription(
    equation_of_state_type=constants.EquationOfStateType.SoaveRedlichKwong,
    surface_tension_model_type=constants.SurfaceTensionType.Leechien,
    viscosity_model=constants.PVTCompositionalViscosityModel.LohrenzBrayClark,
    heavy_components=[HEAVY_COMPONENT_DESCRIPTION],
    light_components=[
        LIGH_COMPONENT_DESCRIPTION,
        LIGH_COMPONENT_DESCRIPTION_OVERWRITE_C3,
    ],
def test_case_description_duplicate_names(default_well):
    """
    Pipes because they are reference by OutputDescription
    Nodes because they are referenced by PipeDescription, WellDescription and OutputDescription
    PVTs names, because of default_model
    Wall Names because of PipeSegmentsDescription
    Material because of WellDescription(stagnant_fluid), CasingSectionDescription, TubingDescription
    """
    well_1 = attr.evolve(default_well, name="Well 1")
    well_2 = attr.evolve(default_well, name="Well 1")

    case = case_description.CaseDescription(
        materials=[
            case_description.MaterialDescription(name="Material"),
            case_description.MaterialDescription(name="Material"),
        ],
        walls=[
            case_description.WallDescription(name="Wall A"),
            case_description.WallDescription(name="Wall A"),
        ],
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT",
            correlations={
                "PVT1": case_description.PvtModelCorrelationDescription(),
            },
            compositions={
                "PVT1":
                case_description.PvtModelCompositionalDescription(fluids={
                    "Fluid 0":
                    case_description.FluidDescription(),
                    "Fluid 1":
                    case_description.FluidDescription(),
                }, ),
                "PVT2":
                case_description.PvtModelCompositionalDescription(
                    fluids={
                        "Fluid 0": case_description.FluidDescription(),
                        "Fluid 1": case_description.FluidDescription(),
                    }),
            },
        ),
        nodes=[
            case_description.NodeDescription(name="ACME",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="ACME",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="Node1",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="FOO",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="FOO",
                                             node_type=NodeCellType.Pressure),
        ],
        pipes=[
            case_description.PipeDescription(
                name="Pipe 1",
                source="ACME",
                target="ACME",
                segments=build_simple_segment(),
            ),
            case_description.PipeDescription(
                name="Pipe 1",
                source="ACME",
                target="ACME",
                segments=build_simple_segment(),
            ),
        ],
        wells=[well_1, well_2],
    )

    expected_msg = dedent("""\
        Elements that can be referenced must have a unique name, found multiples definitions of the following items:
        Fluids:
            - Fluid 0
            - Fluid 1
        Materials:
            - Material
        Nodes:
            - ACME
            - FOO
        PVT:
            - PVT1
        Pipes:
            - Pipe 1
        Walls:
            - Wall A
        Wells:
            - Well 1""")

    with pytest.raises(InvalidReferenceError, match=re.escape(expected_msg)):
        case.ensure_unique_names()