def test_filter_interface(core, project, tree):

    project = deepcopy(project)

    data_menu = DataMenu()
    module_menu = ModuleMenu()
    project_menu = ProjectMenu()

    tree = Tree()

    data_menu.select_database(project, "local")
    project_menu.initiate_pipeline(core, project)
    project_menu.initiate_options(core, project)

    filter_branch = tree.get_branch(core, project,
                                    'Database Filtering Interface')
    new_var = filter_branch.get_input_variable(core, project,
                                               "device.selected_name")
    new_var.set_raw_interface(core, "ExampleWaveDevice")
    new_var.read(core, project)

    module_menu.activate(core, project, "Hydrodynamics")

    project_menu.initiate_filter(core, project)

    assert True
Beispiel #2
0
def database(core, project):

    project = deepcopy(project)
    data_menu = DataMenu()

    data_menu.select_database(project, "testing")
    database = get_database(project.get_database_credentials())

    return database
Beispiel #3
0
def test_DataMenu_get_available_databases(mocker, tmpdir):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    data_menu = DataMenu()

    dbs = data_menu.get_available_databases()

    assert len(dbs) > 0
Beispiel #4
0
def test_DataMenu_select_database_bad_id(mocker, tmpdir, project):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    data_menu = DataMenu()
    project = deepcopy(project)

    with pytest.raises(ValueError):
        data_menu.select_database(project, "bad_id")
Beispiel #5
0
def test_DataMenu_select_database_no_port_dbname(mocker, tmpdir, project):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    data_menu = DataMenu()
    project = deepcopy(project)

    with pytest.raises(RuntimeError):
        data_menu.select_database(project, credentials={"host": "-1.-1.-1.-1"})
Beispiel #6
0
def test_economics_inputs(theme_menu, core, tidal_project, var_tree):

    theme_name = "Economics"
    data_menu = DataMenu()

    project_menu = ProjectMenu()
    project = deepcopy(tidal_project)
    theme_menu.activate(core, project, theme_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)

    economics_branch = var_tree.get_branch(core, project, theme_name)
    economics_input_status = economics_branch.get_input_status(core, project)

    assert "project.estimate_energy_record" in economics_input_status
def test_moorings_inputs(module_menu, core, tidal_project, var_tree):

    mod_name = "Mooring and Foundations"
    data_menu = DataMenu()

    project_menu = ProjectMenu()
    project = deepcopy(tidal_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)

    moorings_branch = var_tree.get_branch(core, project, mod_name)

    moorings_input_status = moorings_branch.get_input_status(core, project)

    assert "device.dry_beam_area" in moorings_input_status
Beispiel #8
0
def test_environmental_inputs(theme_menu, core, tidal_project, var_tree):

    theme_name = "Environmental Impact Assessment (Experimental)"
    data_menu = DataMenu()

    project_menu = ProjectMenu()
    project = deepcopy(tidal_project)
    theme_menu.activate(core, project, theme_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)

    environmental_branch = var_tree.get_branch(core, project, theme_name)

    environmental_input_status = environmental_branch.get_input_status(
        core, project)

    assert "project.hydro_collision_risk_weight" in environmental_input_status
Beispiel #9
0
def test_reliability_inputs(theme_menu, core, tidal_project, var_tree):

    theme_name = "Reliability"
    data_menu = DataMenu()

    project_menu = ProjectMenu()
    project = deepcopy(tidal_project)
    theme_menu.activate(core, project, theme_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)

    reliability_branch = var_tree.get_branch(core, project, theme_name)

    reliability_input_status = reliability_branch.get_input_status(
        core, project)

    assert reliability_input_status is not None
Beispiel #10
0
def test_electrical_inputs(module_menu, core, tidal_project, var_tree):

    mod_name = "Electrical Sub-Systems"
    #    project_menu = ProjectMenu()
    data_menu = DataMenu()
    project_menu = ProjectMenu()

    project = deepcopy(tidal_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)

    electrical_branch = var_tree.get_branch(core, project, mod_name)

    electrical_input_status = electrical_branch.get_input_status(core, project)

    assert "component.transformers" in electrical_input_status
Beispiel #11
0
def test_DataMenu_deselect_database(mocker, tmpdir, project):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    # Create mock connection
    mocker.patch("dtocean_core.menu.check_host_port",
                 return_value=(True, "Mock connection returned"))

    data_menu = DataMenu()
    project = deepcopy(project)

    assert project.get_database_credentials() is None

    dbs = data_menu.get_available_databases()
    db_id = dbs[0]
    data_menu.select_database(project, db_id)

    assert project.get_database_credentials()

    data_menu.deselect_database(project)

    assert project.get_database_credentials() is None
def test_connect_TableDataColumn(core, project, tree):

    var_id = "hidden.available_sites"

    project = deepcopy(project)

    data_menu = DataMenu()
    project_menu = ProjectMenu()

    data_menu.select_database(project, "local")
    project_menu.initiate_pipeline(core, project)

    proj_branch = tree.get_branch(core, project, "Site and System Options")
    var = proj_branch.get_input_variable(core, project, var_id)
    inputs = proj_branch.get_input_status(core, project)

    assert inputs[var_id] == 'satisfied'
    assert 'ExampleSite' in var.get_value(core, project)["site_name"].values
def test_maintenance_inputs(module_menu, core, wave_project, var_tree):
        
    mod_name = 'Operations and Maintenance'
    data_menu = DataMenu()
    project_menu = ProjectMenu()
    
    project = deepcopy(wave_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)
    
    operations_branch = var_tree.get_branch(core, project, mod_name)
   
    
    operations_input_status = operations_branch.get_input_status(core,
                                                                   project)
                                                    
    assert "options.operations_inspections" in operations_input_status
Beispiel #14
0
def test_installation_inputs(module_menu, core, tidal_project, var_tree):
        
    mod_name = "Installation"
    data_menu = DataMenu()
    project_menu = ProjectMenu()
    
    project = deepcopy(tidal_project) 
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    data_menu.load_data(core, project)
    
    installation_branch = var_tree.get_branch(core, project, mod_name)
   
    
    installation_input_status = installation_branch.get_input_status(core,
                                                                   project)
                                                    
    assert "component.ports" in installation_input_status
def test_get_query_interface(core, project, tree):

    mod_name = "Site and System Options"
    var_id = "hidden.available_sites"

    data_menu = DataMenu()
    project_menu = ProjectMenu()

    project = deepcopy(project)

    data_menu.select_database(project, "local")
    project_menu.initiate_pipeline(core, project)

    options_branch = tree.get_branch(core, project, mod_name)
    new_var = options_branch.get_input_variable(core, project, var_id)

    result = new_var._get_query_interface(core, project)

    assert result is not None
Beispiel #16
0
def localhost(core, project):

    project = deepcopy(project)
    data_menu = DataMenu()

    credentials = data_menu._dbconfig["local"]
    project.set_database_credentials(credentials)

    database = get_database(project.get_database_credentials(), echo=True)

    return database
Beispiel #17
0
def test_DataMenu_import_data(mocker, tmpdir, core, project, module_menu):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    data_menu = DataMenu()
    var_tree = Tree()
    project = deepcopy(project)
    mod_name = "Mock Module"

    core.register_level(project, core._markers["register"], "Mock Module")

    module_menu.activate(core, project, mod_name)
    mod_branch = var_tree.get_branch(core, project, mod_name)
    mod_branch.read_test_data(core, project,
                              os.path.join(dir_path, "inputs_wp2_tidal.pkl"))

    pre_length = len(project._pool)

    dts_path = os.path.join(str(tmpdir), "test.dts")

    data_menu.export_data(core, project, dts_path)

    assert os.path.isfile(dts_path)

    data_menu.import_data(core, project, dts_path)

    assert len(project._pool) > pre_length
Beispiel #18
0
def test_DataMenu_update_database(mocker, tmpdir):

    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))

    mocker.patch("dtocean_core.utils.database.UserDataDirectory",
                 return_value=mock_dir)

    data_menu = DataMenu()

    dbs = data_menu.get_available_databases()
    db_id = dbs[0]

    db_dict = data_menu.get_database_dict(db_id)
    data_menu.update_database(db_id, db_dict)

    assert len(config_tmpdir.listdir()) == 1
Beispiel #19
0
def _is_port_open(dbname):

    data_menu = DataMenu()

    return data_menu.check_database(dbname)
def _is_port_open():

    data_menu = DataMenu()

    return data_menu.check_database("local")