def test_edit_project_param(qtbot, monkeypatch): """ Edit the existing parameter to have new values. """ table = ProjectParameterTable() qtbot.addWidget(table) table.model.sync() # Edit both the name and the amount of the first parameter. monkeypatch.setattr( QtWidgets.QInputDialog, "getText", staticmethod(lambda *args, **kwargs: ("test_project", True))) table.model.handle_parameter_rename(table.proxy_model.index(0, 0)) table.model.setData(table.model.index(0, 1), 2.5) # Check that parameter is correctly stored in brightway. assert ProjectParameter.get(name="test_project").amount == 2.5 # Now edit the formula directly (without delegate) with qtbot.waitSignal(signals.parameters_changed, timeout=1000): table.model.setData(table.model.index(0, 2), "2 + 3") assert ProjectParameter.get(name="test_project").amount == 5 # Now edit the formula of the 3rd param to use the 2nd param with qtbot.waitSignal(signals.parameters_changed, timeout=1000): table.model.setData(table.model.index(2, 2), "param_2 + 3") assert ProjectParameter.get(name="param_3").amount == 4
def test_update_alter_mean(qtbot, monkeypatch, ab_app): param = ProjectParameter.create(name="uc2", amount=1) wizard = UncertaintyWizard(param, None) qtbot.addWidget(wizard) wizard.show() # Select the lognormal distribution and set 'loc' and 'scale' fields. wizard.type.distribution.setCurrentIndex(LognormalUncertainty.id) wizard.type.loc.setText("1") wizard.type.scale.setText("0.3") wizard.type.generate_plot() assert wizard.type.complete # Now, monkeypatch Qt to ensure a 'yes' is selected for updating. monkeypatch.setattr(QMessageBox, "question", staticmethod(lambda *args: QMessageBox.Yes)) # Now trigger a 'finish' action with qtbot.waitSignal(signals.parameters_changed, timeout=100): wizard.button(QWizard.FinishButton).click() # Reload param and check that the amount is changed. param = ProjectParameter.get(name="uc2") assert "loc" in param.data and param.amount != 1 loc = param.data["loc"] assert loc == 1 assert np.isclose(np.log(param.amount), loc)
def test_edit_project_param(qtbot): """ Edit the existing parameter to have new values. """ table = ProjectParameterTable() qtbot.addWidget(table) table.sync(table.build_df()) # Edit both the name and the amount of the first parameter. table.rename_parameter(table.proxy_model.index(0, 0), "test_project") table.model.setData(table.model.index(0, 1), 2.5) # Check that parameter is correctly stored in brightway. assert ProjectParameter.get(name="test_project").amount == 2.5 # Now edit the formula directly (without delegate) with qtbot.waitSignal(signals.parameters_changed, timeout=1000): table.model.setData(table.model.index(0, 2), "2 + 3") assert ProjectParameter.get(name="test_project").amount == 5 # Now edit the formula of the 3rd param to use the 2nd param with qtbot.waitSignal(signals.parameters_changed, timeout=1000): table.model.setData(table.model.index(2, 2), "param_2 + 3") assert ProjectParameter.get(name="param_3").amount == 4
def export_db(db_name, filename) : """Export Db and linked parameters""" db = bw.Database(db_name) db_params = DatabaseParameter.select().where(DatabaseParameter.database == db_name) # Export Db params db.metadata["database_parameters"] = [param_data(param) for param in db_params] # List of all project params used in this dataset used_project_params = list(param.name for param in _listParams(db_name) if param.dbname is None) if len(used_project_params) > 0 : error('Warning : this DB uses project parameters that are exported as well and might override project params at import time : ', used_project_params) proj_params = list(ProjectParameter.get(ProjectParameter.name==name) for name in used_project_params) db.metadata["project_parameters"] = [param_data(param) for param in proj_params] BW2Package._write_file(filename, [BW2Package._prepare_obj(db, False)])
def test_update_uncertainty(qtbot, ab_app): """Using the signal/controller setup, update the uncertainty of a parameter""" param = ProjectParameter.create(name="uc1", amount=3) wizard = UncertaintyWizard(param, None) qtbot.addWidget(wizard) wizard.show() wizard.type.distribution.setCurrentIndex(TriangularUncertainty.id) wizard.type.minimum.setText("1") wizard.type.maximum.setText("5") wizard.type.generate_plot() assert wizard.type.complete # Now trigger a 'finish' action with qtbot.waitSignal(signals.parameters_changed, timeout=100): wizard.button(QWizard.FinishButton).click() # Reload param param = ProjectParameter.get(name="uc1") assert "loc" in param.data and param.data["loc"] == 3