示例#1
0
def test_delete_activity_param(qtbot):
    """ Remove activity parameters.
    """
    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.activity_table

    rect = table.visualRect(table.proxy_model.index(0, 0))
    qtbot.mouseClick(table.viewport(), QtCore.Qt.LeftButton, pos=rect.center())

    group = table.get_current_group()

    # Now delete the parameter for the selected row.
    table.delete_parameter(table.currentIndex())
    assert table.rowCount() == 2
    assert ActivityParameter.select().count() == 2
    assert Group.select().where(Group.name == group).exists()

    # And delete the other two parameters one by one.
    table.delete_parameter(table.proxy_model.index(0, 0))
    table.delete_parameter(table.proxy_model.index(0, 0))
    assert table.rowCount() == 0
    assert ActivityParameter.select().count() == 0
    # Group is automatically removed with the last parameter gone
    assert not Group.select().where(Group.name == group).exists()
示例#2
0
def test_create_project_param(qtbot):
    """ Create a single Project parameter.

    Does not user the overarching application due to mouseClick failing
    """
    assert bw.projects.current == "pytest_project"
    assert ProjectParameter.select().count() == 0

    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.project_table

    bw.parameters.new_project_parameters([
        {
            "name": "param_1",
            "amount": 1.0
        },
        {
            "name": "param_2",
            "amount": 1.0
        },
        {
            "name": "param_3",
            "amount": 1.0
        },
    ])
    table.model.sync()
    assert table.rowCount() == 3

    # New parameter is named 'param_1'
    assert table.model.index(0, 0).data() == "param_1"
    assert ProjectParameter.select().count() == 3
    assert ProjectParameter.select().where(
        ProjectParameter.name == "param_1").exists()
示例#3
0
def test_create_project_param(qtbot):
    """ Create a single Project parameter.

    Does not user the overarching application due to mouseClick failing
    """
    assert bw.projects.current == "pytest_project"
    assert ProjectParameter.select().count() == 0

    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.project_table

    signal_list = [
        signals.parameters_changed, signals.parameters_changed,
        signals.parameters_changed
    ]
    with qtbot.waitSignals(signal_list, timeout=1000):
        qtbot.mouseClick(project_db_tab.new_project_param,
                         QtCore.Qt.LeftButton)
        qtbot.mouseClick(project_db_tab.new_project_param,
                         QtCore.Qt.LeftButton)
        qtbot.mouseClick(project_db_tab.new_project_param,
                         QtCore.Qt.LeftButton)
    assert table.rowCount() == 3

    # New parameter is named 'param_1'
    assert table.model.index(0, 0).data() == "param_1"
    assert ProjectParameter.select().count() == 3
    assert ProjectParameter.select().where(
        ProjectParameter.name == "param_1").exists()
示例#4
0
def test_delete_database_params(qtbot):
    """ Attempt to delete a parameter.
    """
    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.database_table

    # Check that we can delete the parameter and remove it.
    proxy = table.proxy_model.index(1, 0)
    assert table.get_parameter(proxy).is_deletable()
    table.delete_parameter(proxy)

    # Now we have two rows left
    assert table.rowCount() == 2
    assert DatabaseParameter.select().count() == 2
示例#5
0
def test_create_database_params(qtbot):
    """ Create three database parameters

    Does not user the overarching application due to mouseClick failing
    """
    assert DatabaseParameter.select().count() == 0

    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.database_table

    # Open the database foldout
    assert not table.isHidden()
    with qtbot.waitSignal(project_db_tab.show_database_params.stateChanged,
                          timeout=1000):
        qtbot.mouseClick(project_db_tab.show_database_params,
                         QtCore.Qt.LeftButton)
    assert table.isHidden()
    project_db_tab.show_database_params.toggle()

    # Generate a few database parameters
    bw.parameters.new_database_parameters([
        {
            "name": "param_2",
            "amount": 1.0
        },
        {
            "name": "param_3",
            "amount": 1.0
        },
        {
            "name": "param_4",
            "amount": 1.0
        },
    ],
                                          database="biosphere3")
    table.model.sync()

    # First created parameter is named 'param_2'
    assert table.model.index(0, 0).data() == "param_2"
    assert table.rowCount() == 3
    assert DatabaseParameter.select().count() == 3
示例#6
0
def test_create_activity_param(qtbot):
    """ Create several activity parameters.

    TODO: Figure out some way of performing a drag action between tables.
     Use method calls for now.
     Until the above is implemented, take shortcuts and don't check db validity
    """
    project_db_tab = ParameterDefinitionTab()
    qtbot.addWidget(project_db_tab)
    project_db_tab.build_tables()
    table = project_db_tab.activity_table

    # Open the order column just because we can
    col = table.COLUMNS.index("order")
    assert table.isColumnHidden(col)
    with qtbot.waitSignal(project_db_tab.show_order.stateChanged,
                          timeout=1000):
        qtbot.mouseClick(project_db_tab.show_order, QtCore.Qt.LeftButton)
    assert not table.isColumnHidden(col)

    # Create multiple parameters for a single activity
    act_key = ("testdb", "act1")
    for _ in range(3):
        table.add_parameter(act_key)

    # Test created parameters
    assert ActivityParameter.select().count() == 3
    # First of the multiple parameters
    assert table.proxy_model.index(0, 0).data() == "act_1"
    # Second of the multiple parameters
    assert table.proxy_model.index(1, 0).data() == "act_2"
    # The group name for the `testdb` parameters is the same.
    loc = table.visualRect(table.proxy_model.index(0, 0))
    qtbot.mouseClick(table.viewport(), QtCore.Qt.LeftButton, pos=loc.center())
    group = table.get_current_group()
    assert table.proxy_model.index(
        2, table.COLUMNS.index("group")).data() == group