Repository: Avaiga/taipy
File: tests/core/scenario/test_scenario_manager.py (Python)

Code before:
    all_scenarios = tp.get_scenarios()
    assert not_primary_scenario in all_scenarios

    primary_scenarios = _ScenarioManager._get_primary_scenarios()
    assert not_primary_scenario not in primary_scenarios

    primary_scenarios_sorted_by_name = [scenario_2, scenario_1, scenario_3, scenario_4]
    assert primary_scenarios_sorted_by_name == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="name")

    scenarios_with_same_config_id = [scenario_2, scenario_3, scenario_4]
    scenarios_with_same_config_id.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_config_id = [scenario_1, scenarios_with_same_config_id[0], scenarios_with_same_config_id[1], scenarios_with_same_config_id[2]]
    assert primary_scenarios_sorted_by_config_id == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="config_id")

    scenarios_sorted_by_id = [scenario_1, scenario_2, scenario_3, scenario_4]
    scenarios_sorted_by_id.sort(key=lambda x: x.id)
    assert scenarios_sorted_by_id == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="id")

    primary_scenarios_sorted_by_creation_date = [scenario_1, scenario_2, scenario_4,scenario_3]
    assert primary_scenarios_sorted_by_creation_date == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False,
                                                                                         sort_key="creation_date")

    scenarios_with_same_tags = [scenario_1, scenario_3]
    scenarios_with_same_tags.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_tags = [scenario_4, scenario_2, scenarios_with_same_tags[0], scenarios_with_same_tags[1]]
    assert primary_scenarios_sorted_by_tags == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="tags")

    primary_scenarios_sorted_by_name_descending_order = [scenario_4, scenario_3, scenario_1, scenario_2]
    assert primary_scenarios_sorted_by_name_descending_order == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=True, sort_key="name"
    )


def test_hard_delete_one_single_scenario_with_scenario_data_nodes():
    dn_input_config = Config.configure_data_node("my_input", "in_memory", scope=Scope.SCENARIO, default_data="testing")
    dn_output_config = Config.configure_data_node("my_output", "in_memory", scope=Scope.SCENARIO)
    task_config = Config.configure_task("task_config", print, dn_input_config, dn_output_config)
    scenario_config = Config.configure_scenario("scenario_config", [task_config])
    scenario_config.add_sequences({"sequence_config": [task_config]})

    scenario = _ScenarioManager._create(scenario_config)
    _ScenarioManager._submit(scenario.id)

    assert len(_ScenarioManager._get_all()) == 1
    assert len(_SequenceManager._get_all()) == 1
    assert len(_TaskManager._get_all()) == 1
    assert len(_DataManager._get_all()) == 2
    assert len(_JobManager._get_all()) == 1
    _ScenarioManager._hard_delete(scenario.id)
    assert len(_ScenarioManager._get_all()) == 0
    assert len(_SequenceManager._get_all()) == 0

Review comment (refactor):
E501 Line too long

```suggestion
    primary_scenarios_sorted_by_tags = [scenario_4,
                                        scenario_2, scenarios_with_same_tags[0],
                                        scenarios_with_same_tags[1]]
    assert primary_scenarios_sorted_by_tags == _ScenarioManager._sort_scenarios(primary_scenarios,
                                 descending=False,
                                 sort_key="tags")
```

Code after:

    all_scenarios = tp.get_scenarios()
    assert not_primary_scenario in all_scenarios

    primary_scenarios = _ScenarioManager._get_primary_scenarios()
    assert not_primary_scenario not in primary_scenarios

    primary_scenarios_sorted_by_name = [scenario_2, scenario_1, scenario_3, scenario_4]
    assert primary_scenarios_sorted_by_name == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="name"
    )

    scenarios_with_same_config_id = [scenario_2, scenario_3, scenario_4]
    scenarios_with_same_config_id.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_config_id = [
        scenario_1,
        scenarios_with_same_config_id[0],
        scenarios_with_same_config_id[1],
        scenarios_with_same_config_id[2],
    ]
    assert primary_scenarios_sorted_by_config_id == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="config_id"
    )

    scenarios_sorted_by_id = [scenario_1, scenario_2, scenario_3, scenario_4]
    scenarios_sorted_by_id.sort(key=lambda x: x.id)
    assert scenarios_sorted_by_id == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="id"
    )

    primary_scenarios_sorted_by_creation_date = [scenario_1, scenario_2, scenario_4, scenario_3]
    assert primary_scenarios_sorted_by_creation_date == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="creation_date"
    )

    scenarios_with_same_tags = [scenario_1, scenario_3]
    scenarios_with_same_tags.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_tags = [
        scenario_4,
        scenario_2,
        scenarios_with_same_tags[0],
        scenarios_with_same_tags[1],
    ]
    assert primary_scenarios_sorted_by_tags == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="tags"
    )

    primary_scenarios_sorted_by_name_descending_order = [scenario_4, scenario_3, scenario_1, scenario_2]
    assert primary_scenarios_sorted_by_name_descending_order == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=True, sort_key="name"
    )