def test_loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint(
            self):
        """
        """

        m = build_model({}, 'simple_conversion_plus,one_day,investment_costs')
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           'conversion_plus_prod_con_to_zero_constraint')

        m = build_model(
            {
                'techs.test_conversion_plus.constraints.carrier_ratios.carrier_out_2.heat':
                'file=carrier_ratio.csv'
            }, 'simple_conversion_plus,two_hours,investment_costs')
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           'conversion_plus_prod_con_to_zero_constraint')

        m = build_model(
            {
                'techs.test_conversion_plus.constraints.carrier_ratios.carrier_out_2.heat':
                'file=carrier_ratio.csv'
            }, 'simple_conversion_plus,one_day,investment_costs')
        m.run(build_only=True)
        assert hasattr(m._backend_model,
                       'conversion_plus_prod_con_to_zero_constraint')
        assert check_variable_exists(
            m._backend_model, 'conversion_plus_prod_con_to_zero_constraint',
            'carrier_prod')
        assert hasattr(
            m._backend_model,
            'loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint')

        m = build_model(
            {
                'techs.test_conversion_plus': {
                    'essentials.carrier_in': ['gas', 'coal'],
                    'essentials.primary_carrier_in': 'gas',
                    'constraints.carrier_ratios': {
                        'carrier_out_2.heat': 'file=carrier_ratio.csv',
                        'carrier_in.coal': 'file=carrier_ratio.csv'
                    }
                }
            }, 'simple_conversion_plus,one_day,investment_costs')
        m.run(build_only=True)
        assert hasattr(m._backend_model,
                       'conversion_plus_prod_con_to_zero_constraint')
        assert check_variable_exists(
            m._backend_model, 'conversion_plus_prod_con_to_zero_constraint',
            'carrier_prod')
        assert check_variable_exists(
            m._backend_model, 'conversion_plus_prod_con_to_zero_constraint',
            'carrier_con')
        assert hasattr(
            m._backend_model,
            'loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint')
    def test_loc_techs_cost_var_conversion_plus_constraint(self):
        """
        sets.loc_techs_om_cost_conversion_plus,
        """
        # no conversion_plus = no constraint
        m = build_model(
            {"techs.test_supply_elec.costs.monetary.om_prod": 0.1},
            "simple_supply,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           "cost_var_conversion_plus_constraint")

        # no conversion_plus = no constraint
        m = build_model(
            {"techs.test_conversion.costs.monetary.om_prod": 0.1},
            "simple_conversion,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           "cost_var_conversion_plus_constraint")

        # no variable costs for conversion_plus = no constraint
        m = build_model({},
                        "simple_conversion_plus,two_hours,investment_costs")
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           "cost_var_conversion_plus_constraint")

        # om_prod creates constraint and populates it with carrier_prod driven cost
        m = build_model(
            {"techs.test_conversion_plus.costs.monetary.om_prod": 0.1},
            "simple_conversion_plus,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert hasattr(m._backend_model, "cost_var_conversion_plus_constraint")
        assert check_variable_exists(m._backend_model,
                                     "cost_var_conversion_plus_constraint",
                                     "carrier_prod")
        assert not check_variable_exists(
            m._backend_model, "cost_var_conversion_plus_constraint",
            "carrier_con")

        # om_con creates constraint and populates it with carrier_con driven cost
        m = build_model(
            {"techs.test_conversion_plus.costs.monetary.om_con": 0.1},
            "simple_conversion_plus,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert hasattr(m._backend_model, "cost_var_conversion_plus_constraint")
        assert check_variable_exists(m._backend_model,
                                     "cost_var_conversion_plus_constraint",
                                     "carrier_con")
        assert not check_variable_exists(
            m._backend_model, "cost_var_conversion_plus_constraint",
            "carrier_prod")
    def test_loc_techs_cost_var_conversion_plus_constraint(self, flow):
        """
        sets.loc_techs_om_cost_conversion_plus,
        """

        # om_prod creates constraint and populates it with carrier_prod driven cost
        m = build_model(
            {f"techs.test_conversion_plus.costs.monetary.om_{flow}": 0.1},
            "simple_conversion_plus,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert hasattr(m._backend_model, "cost_var")
        assert check_variable_exists(m._backend_model, "cost_var",
                                     f"carrier_{flow}")
        assert not check_variable_exists(m._backend_model, "cost_var",
                                         "carrier_prodcon".replace(flow, ""))
        assert all("test_conversion_plus" in i
                   for i in m._backend_model.cost_var._index)
    def test_loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint(
            self):
        """
        """

        m = build_model({}, "simple_conversion_plus,one_day,investment_costs")
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           "conversion_plus_prod_con_to_zero_constraint")

        m = build_model(
            {
                "techs.test_conversion_plus.constraints.carrier_ratios.carrier_out_2.heat":
                "file=carrier_ratio.csv"
            },
            "simple_conversion_plus,two_hours,investment_costs",
        )
        m.run(build_only=True)
        assert not hasattr(m._backend_model,
                           "conversion_plus_prod_con_to_zero_constraint")

        m = build_model(
            {
                "techs.test_conversion_plus.constraints.carrier_ratios.carrier_out_2.heat":
                "file=carrier_ratio.csv"
            },
            "simple_conversion_plus,one_day,investment_costs",
        )
        m.run(build_only=True)
        assert hasattr(m._backend_model,
                       "conversion_plus_prod_con_to_zero_constraint")
        assert check_variable_exists(
            m._backend_model,
            "conversion_plus_prod_con_to_zero_constraint",
            "carrier_prod",
        )
        assert hasattr(
            m._backend_model,
            "loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint",
        )

        m = build_model(
            {
                "techs.test_conversion_plus": {
                    "essentials.carrier_in": ["gas", "coal"],
                    "essentials.primary_carrier_in": "gas",
                    "constraints.carrier_ratios": {
                        "carrier_out_2.heat": "file=carrier_ratio.csv",
                        "carrier_in.coal": "file=carrier_ratio.csv",
                    },
                }
            },
            "simple_conversion_plus,one_day,investment_costs",
        )
        m.run(build_only=True)
        assert hasattr(m._backend_model,
                       "conversion_plus_prod_con_to_zero_constraint")
        assert check_variable_exists(
            m._backend_model,
            "conversion_plus_prod_con_to_zero_constraint",
            "carrier_prod",
        )
        assert check_variable_exists(
            m._backend_model,
            "conversion_plus_prod_con_to_zero_constraint",
            "carrier_con",
        )
        assert hasattr(
            m._backend_model,
            "loc_tech_carrier_tiers_conversion_plus_zero_ratio_constraint",
        )