Example #1
0
def test_get_electrical_interface(module_menu, core, tidal_project, var_tree):

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

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

    electrical_branch = var_tree.get_branch(core, project, mod_name)
    electrical_branch.read_test_data(core, project,
                                     os.path.join(dir_path, "inputs_wp3.pkl"))
    electrical_branch.read_auto(core, project)

    can_execute = module_menu.is_executable(core, project, mod_name)

    if not can_execute:

        inputs = electrical_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core, project, mod_name)

    assert interface.data.voltage is not None
Example #2
0
def test_get_reliability_interface(theme_menu, core, tidal_project, var_tree):

    theme_name = "Reliability"
    #    project_menu = ProjectMenu()

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

    reliability_branch = var_tree.get_branch(core, project, theme_name)
    reliability_branch.read_test_data(
        core, project, os.path.join(dir_path, "inputs_reliability.pkl"))
    reliability_branch.read_auto(core, project)

    can_execute = theme_menu.is_executable(core, project, theme_name)

    if not can_execute:

        inputs = reliability_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "themes")
    interface = connector.get_interface(core, project, theme_name)

    assert interface.data.mission_time is not None
def test_get_maintenance_interface(module_menu, core, wave_project, var_tree):
    
    mod_name = 'Operations and Maintenance'
    
    project_menu = ProjectMenu()
    project = deepcopy(wave_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    
    operations_branch = var_tree.get_branch(core, project, mod_name)
    operations_branch.read_test_data(core,
                                     project,
                                     os.path.join(dir_path,
                                                  "inputs_wp6.pkl"))
    operations_branch.read_auto(core, project)
    
    can_execute = module_menu.is_executable(core, project,  mod_name)
    
    if not can_execute:
        
        inputs = operations_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute
        
    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core,
                                        project,
                                        mod_name)
                                        
    assert interface.data.system_type is not None
Example #4
0
def test_get_installation_interface(module_menu, core, tidal_project,
                                    var_tree):
    
    mod_name = "Installation"
    
    project_menu = ProjectMenu()
    project = deepcopy(tidal_project) 
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    
    installation_branch = var_tree.get_branch(core, project, mod_name)
    installation_branch.read_test_data(core,
                                     project,
                                     os.path.join(dir_path,
                                                  "inputs_wp5.pkl"))
    installation_branch.read_auto(core, project)
    
    can_execute = module_menu.is_executable(core, project,  mod_name)
    
    if not can_execute:
        
        inputs = installation_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute
        
    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core,
                                        project,
                                        mod_name)
                                        
    assert interface.data.site is not None
def test_get_tidal_interface(module_menu, core, tidal_project, var_tree):
        
    mod_name = "Hydrodynamics"
#    project_menu = ProjectMenu()
    
    project_menu = ProjectMenu()
    project = deepcopy(tidal_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    
    hydro_branch = var_tree.get_branch(core, project, mod_name)
    hydro_branch.read_test_data(core,
                                project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
                                                       
    can_execute = module_menu.is_executable(core, project,  mod_name)
    
    if not can_execute:
        
        inputs = hydro_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute
        
    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core,
                                        project,
                                        mod_name)
                                        
    assert interface.data.perf_curves is not None
Example #6
0
def test_get_environmental_interface(theme_menu, core, tidal_project,
                                     var_tree):

    theme_name = "Environmental Impact Assessment (Experimental)"

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

    environmental_branch = var_tree.get_branch(core, project, theme_name)
    environmental_branch.read_test_data(
        core, project, os.path.join(dir_path, "inputs_environmental.pkl"))
    environmental_branch.read_auto(core, project)

    can_execute = theme_menu.is_executable(core, project, theme_name)

    if not can_execute:

        inputs = environmental_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "themes")
    interface = connector.get_interface(core, project, theme_name)

    #
    assert interface.data.layout is not None
Example #7
0
def test_get_economics_interface(theme_menu, core, tidal_project, var_tree):

    theme_name = "Economics"

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

    economics_branch = var_tree.get_branch(core, project, theme_name)
    economics_branch.read_test_data(
        core, project, os.path.join(dir_path, "inputs_economics.pkl"))
    economics_branch.read_auto(core, project)

    can_execute = theme_menu.is_executable(core, project, theme_name)

    if not can_execute:

        inputs = economics_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "themes")
    interface = connector.get_interface(core, project, theme_name)

    assert interface.data.electrical_bom is not None
def test_maintenance_interface_entry(module_menu,
                                     core,
                                     wave_project,
                                     var_tree,
                                     mocker,
                                     tmpdir):
    
    # Make a source directory with some files
    config_tmpdir = tmpdir.mkdir("config")
    mock_dir = Directory(str(config_tmpdir))
        
    mocker.patch('dtocean_core.interfaces.maintenance.UserDataDirectory',
                 return_value=mock_dir,
                 autospec=True)
        
    mod_name = 'Operations and Maintenance'
    
    project_menu = ProjectMenu()
    project = deepcopy(wave_project)
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    
    operations_branch = var_tree.get_branch(core, project, mod_name)
    operations_branch.read_test_data(core,
                                     project,
                                     os.path.join(dir_path,
                                                  "inputs_wp6.pkl"))
    operations_branch.read_auto(core, project)
    
    can_execute = module_menu.is_executable(core, project,  mod_name)
    
    if not can_execute:
        
        inputs = operations_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute
        
    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core,
                                        project,
                                        mod_name)
                                        
    interface.connect(debug_entry=True)
                                        
    debugdir = config_tmpdir.join("..", "debug")
    
    assert len(debugdir.listdir()) == 1
Example #9
0
def test_reliability_interface_entry(theme_menu, core, tidal_project, var_tree,
                                     mocker, tmpdir):

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

    mocker.patch('dtocean_core.interfaces.reliability.UserDataDirectory',
                 return_value=mock_dir,
                 autospec=True)

    theme_name = "Reliability"
    #    project_menu = ProjectMenu()

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

    reliability_branch = var_tree.get_branch(core, project, theme_name)
    reliability_branch.read_test_data(
        core, project, os.path.join(dir_path, "inputs_reliability.pkl"))
    reliability_branch.read_auto(core, project)

    can_execute = theme_menu.is_executable(core, project, theme_name)

    if not can_execute:

        inputs = reliability_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "themes")
    interface = connector.get_interface(core, project, theme_name)

    interface.connect(debug_entry=True)

    debugdir = config_tmpdir.join("..", "debug")

    assert len(debugdir.listdir()) == 1
def test_tidal_interface_entry_fail(module_menu,
                                    core,
                                    tidal_project,
                                    var_tree):
        
    mod_name = "Hydrodynamics"
    
    project_menu = ProjectMenu()
    project = deepcopy(tidal_project) 
    module_menu.activate(core, project, mod_name)
    project_menu.initiate_dataflow(core, project)
    
    hydro_branch = var_tree.get_branch(core, project, mod_name)
    hydro_branch.read_test_data(core,
                                project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
    
    user_layout = hydro_branch.get_input_variable(core,
                                                  project,
                                                  "options.user_array_layout")
    user_layout.set_raw_interface(core, None)
    user_layout.read(core, project)
                                                       
    can_execute = module_menu.is_executable(core, project, mod_name)
    
    if not can_execute:
        
        inputs = hydro_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute
        
    connector = _get_connector(project, "modules")
    interface = connector.get_interface(core,
                                        project,
                                        mod_name)
    
    with pytest.raises(ValueError):
        interface.connect(debug_entry=True)
def test_options_interface_sites(core, wave_project):

    project_menu = ProjectMenu()
    var_tree = Tree()
    interface_name = "Site and System Options"

    project = deepcopy(wave_project)
    project_menu.activate(core, project, interface_name)

    site_system_branch = var_tree.get_branch(core, project, interface_name)
    available_sites = site_system_branch.get_input_variable(
        core, project, "hidden.available_sites")

    available_sites_dict = {
        "id": [1, 2],
        "site_name": ["a", "b"],
        "lease_area_proj4_string": ["a", "b"]
    }
    available_sites_df = pd.DataFrame(available_sites_dict)

    available_sites.set_raw_interface(core, available_sites_df)
    available_sites.read(core, project)

    can_execute = project_menu.is_executable(core, project, interface_name)

    if not can_execute:

        inputs = site_system_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "project")
    interface = connector.get_interface(core, project, interface_name)

    interface.connect()

    assert interface.data.site_names.equals(available_sites_df["site_name"])
    assert interface.data.corridor_selected == False
    assert interface.data.lease_selected == False
def test_system_type_interface(core, wave_project):

    project_menu = ProjectMenu()
    var_tree = Tree()
    interface_name = "System Type Selection"

    project = deepcopy(wave_project)
    system_type_branch = var_tree.get_branch(core, project, interface_name)

    can_execute = project_menu.is_executable(core, project, interface_name)

    if not can_execute:

        inputs = system_type_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "project")
    interface = connector.get_interface(core, project, interface_name)

    interface.connect()

    assert interface.data.output == True
def test_options_interface_systems(core, wave_project):

    project_menu = ProjectMenu()
    var_tree = Tree()
    interface_name = "Site and System Options"

    project = deepcopy(wave_project)
    project_menu.activate(core, project, interface_name)

    site_system_branch = var_tree.get_branch(core, project, interface_name)
    available_systems = site_system_branch.get_input_variable(
        core, project, "hidden.available_systems")

    available_systems_dict = {
        "id": [1, 2],
        "description": ["a", "b"],
        "device_type": ["a", "Wave Floating"]
    }
    available_systems_df = pd.DataFrame(available_systems_dict)

    available_systems.set_raw_interface(core, available_systems_df)
    available_systems.read(core, project)

    can_execute = project_menu.is_executable(core, project, interface_name)

    if not can_execute:

        inputs = site_system_branch.get_input_status(core, project)
        pprint(inputs)
        assert can_execute

    connector = _get_connector(project, "project")
    interface = connector.get_interface(core, project, interface_name)

    interface.connect()

    assert interface.data.system_names.equals(pd.Series(["b"]))
Example #14
0
    def _make_menus(self, shell, position):

        proxy_indexes = self.treeView.selectedIndexes()
        proxy_index = proxy_indexes[0]
        controller = self._find_controller(proxy_index)

        if isinstance(controller, InputBranchControl):

            # Set the widget action
            self._test_data_picker.buttonBox.button(
                QtGui.QDialogButtonBox.Ok).clicked.disconnect()
            self._test_data_picker.buttonBox.button(
                QtGui.QDialogButtonBox.Ok).clicked.connect(
                    lambda: self._read_test_data(shell, controller))
            self._test_data_picker.buttonBox.button(
                QtGui.QDialogButtonBox.Ok).clicked.connect(
                    self._test_data_picker.close)

            # Build module and theme context menu
            if controller._hub_title in ["Modules", "Assessment"]:

                menu = QtGui.QMenu()

                # Enable tooltips
                tips = lambda action: QtGui.QToolTip.showText(
                    QtGui.QCursor.pos(), action.toolTip(), menu,
                    menu.actionGeometry(action))
                menu.hovered.connect(tips)

                if controller._hub_title == "Modules":

                    # Can't reset or insepct unless the interface has executed
                    connector = _get_connector(shell.project, "modules")

                    active = connector.is_interface_completed(
                        shell.core, shell.project, controller._title)

                    action = menu.addAction('Inspect',
                                            lambda: controller._inspect(shell))
                    action.setToolTip('Inspect results following '
                                      'execution of this module')
                    action.setEnabled(active)

                    action = menu.addAction('Reset',
                                            lambda: controller._reset(shell))
                    action.setToolTip('Reset simulation prior to '
                                      'execution of this module')
                    action.setEnabled(active)

                menu.addAction('Load test data...',
                               self._test_data_picker.show)
                menu.exec_(self.treeView.mapToGlobal(position))

        elif isinstance(controller, OutputBranchControl):

            # Build module context menu
            if controller._hub_title == "Modules":

                menu = QtGui.QMenu()
                menu.addAction('Inspect', lambda: controller._inspect(shell))
                menu.exec_(self.treeView.mapToGlobal(position))

        return