def __createMenu(self): file_menu = self.menuBar().addMenu("&File") file_menu.addAction("Close", self.close) self.__view_menu = self.menuBar().addMenu("&View") self.__help_menu = self.menuBar().addMenu("&Help") """:type: QMenu""" """ @rtype: list of QAction """ show_about = self.__help_menu.addAction("About") show_about.setMenuRole(QAction.ApplicationSpecificRole) show_about.triggered.connect(self.__showAboutMessage) if sys.version_info.major >= 3: pm = ErtPluginManager() help_links = pm.get_help_links() else: with pkg_resources.resource_stream( "ert_gui", os.path.join("resources", "gui", "help", "help_links.yml")) as stream: help_links = yaml.safe_load(stream) for menu_label, link in help_links.items(): help_link_item = self.__help_menu.addAction(menu_label) help_link_item.setMenuRole(QAction.ApplicationSpecificRole) help_link_item.triggered.connect( functools.partial(webbrowser.open, link))
def test_add_logging_handle(tmpdir): with tmpdir.as_cwd(): pm = ErtPluginManager(plugins=[dummy_plugins]) pm.add_logging_handle_to_root(logging.getLogger()) logging.critical("I should write this to spam.log") with open("spam.log", encoding="utf-8") as fin: result = fin.read() assert "I should write this to spam.log" in result
def test_plugin_manager_python_2(self): pm = ErtPluginManager() self.assertEqual(pm.get_installable_workflow_jobs(), None) self.assertEqual(pm.get_installable_jobs(), None) self.assertEqual(pm.get_flow_config_path(), None) self.assertEqual(pm.get_ecl100_config_path(), None) self.assertEqual(pm.get_ecl300_config_path(), None) self.assertEqual(pm.get_rms_config_path(), None) self.assertEqual(pm.get_help_links(), None) self.assertEqual(pm.get_site_config_content(), None)
def test_workflows_merge(monkeypatch, tmpdir): expected_result = { "wf_job1": "/dummy/path/wf_job1", "wf_job2": "/dummy/path/wf_job2", "some_func": str(tmpdir / "SOME_FUNC"), } tempfile_mock = Mock(return_value=tmpdir) monkeypatch.setattr(tempfile, "mkdtemp", tempfile_mock) pm = ErtPluginManager(plugins=[dummy_plugins]) result = pm.get_installable_workflow_jobs() assert result == expected_result
def test_workflows_merge_duplicate(caplog): pm = ErtPluginManager(plugins=[dummy_plugins]) dict_1 = {"some_job": "/a/path"} dict_2 = {"some_job": "/a/path"} with caplog.at_level(logging.INFO): result = pm._merge_internal_jobs(dict_1, dict_2) assert result == {"some_job": "/a/path"} assert ("Duplicate key: some_job in workflow hook implementations, " "config path 1: /a/path, config path 2: /a/path") in caplog.text
def test_job_documentation(self): pm = ErtPluginManager(plugins=[dummy_plugins]) expected = { "job1": { "config_file": "/dummy/path/job1", "source_package": "dummy", "source_function_name": "installable_jobs", "description": "job description", "examples": "example 1 and example 2", "category": "test.category.for.job", }, "job2": { "config_file": "/dummy/path/job2", "source_package": "dummy", "source_function_name": "installable_jobs", }, } assert pm.get_documentation_for_jobs() == expected
def __createMenu(self): file_menu = self.menuBar().addMenu("&File") file_menu.addAction("Close", self.close) self.__view_menu = self.menuBar().addMenu("&View") self.__help_menu = self.menuBar().addMenu("&Help") """:type: QMenu""" """ @rtype: list of QAction """ show_about = self.__help_menu.addAction("About") show_about.setMenuRole(QAction.ApplicationSpecificRole) show_about.triggered.connect(self.__showAboutMessage) pm = ErtPluginManager() help_links = pm.get_help_links() for menu_label, link in help_links.items(): help_link_item = self.__help_menu.addAction(menu_label) help_link_item.setMenuRole(QAction.ApplicationSpecificRole) help_link_item.triggered.connect( functools.partial(webbrowser.open, link))
class ErtWorkflowDocumentation(_ErtDocumentation): pm = ErtPluginManager() _JOBS = pm.get_documentation_for_workflows() _TITLE = "Workflow jobs" _SECTION_ID = "ert-workflow-jobs" def run(self): section_id = ErtWorkflowDocumentation._SECTION_ID title = ErtWorkflowDocumentation._TITLE return self._generate_job_documentation(ErtWorkflowDocumentation._JOBS, section_id, title)
class ErtForwardModelDocumentation(_ErtDocumentation): pm = ErtPluginManager() _JOBS = pm.get_documentation_for_jobs() _TITLE = "Forward models" _SECTION_ID = "ert-forward-models" def run(self): section_id = ErtForwardModelDocumentation._SECTION_ID title = ErtForwardModelDocumentation._TITLE return self._generate_job_documentation( ErtForwardModelDocumentation._JOBS, section_id, title)
def test_no_plugins(self): pm = ErtPluginManager(plugins=[ert_shared.hook_implementations]) self.assertDictEqual({"GitHub page": "https://github.com/equinor/ert"}, pm.get_help_links()) self.assertIsNone(pm.get_flow_config_path()) self.assertIsNone(pm.get_ecl100_config_path()) self.assertIsNone(pm.get_ecl300_config_path()) self.assertIsNone(pm.get_rms_config_path()) self.assertLess(0, len(pm.get_installable_jobs())) self.assertLess(0, len(pm.get_installable_workflow_jobs())) self.assertListEqual( [ "-- Content below originated from ert (site_config_lines)", "JOB_SCRIPT job_dispatch.py", "QUEUE_OPTION LOCAL MAX_RUNNING 1", ], pm._site_config_lines(), )
class ErtWorkflowDocumentation(_ErtDocumentation): pm = ErtPluginManager() _JOBS = pm.get_documentation_for_workflows() _TITLE = "Workflow jobs" _SECTION_ID = "ert-workflow-jobs" def run(self): section_id = ErtWorkflowDocumentation._SECTION_ID title = ErtWorkflowDocumentation._TITLE if sys.version_info.major >= 3: return self._generate_job_documentation( ErtWorkflowDocumentation._JOBS, section_id, title) else: return _create_py2_message(section_id, title)
def test_with_plugins(self): pm = ErtPluginManager( plugins=[ert_shared.hook_implementations, dummy_plugins]) self.assertDictEqual( { "GitHub page": "https://github.com/equinor/ert", "test": "test", "test2": "test", }, pm.get_help_links(), ) self.assertEqual("/dummy/path/flow_config.yml", pm.get_flow_config_path()) self.assertEqual("/dummy/path/rms_config.yml", pm.get_rms_config_path()) self.assertEqual("/dummy/path/ecl100_config.yml", pm.get_ecl100_config_path()) self.assertEqual("/dummy/path/ecl300_config.yml", pm.get_ecl300_config_path()) self.assertIn(("job1", "/dummy/path/job1"), pm.get_installable_jobs().items()) self.assertIn(("job2", "/dummy/path/job2"), pm.get_installable_jobs().items()) self.assertIn( ("wf_job1", "/dummy/path/wf_job1"), pm._get_config_workflow_jobs().items(), ) self.assertIn( ("wf_job2", "/dummy/path/wf_job2"), pm._get_config_workflow_jobs().items(), ) self.assertListEqual( [ "-- Content below originated from ert (site_config_lines)", "JOB_SCRIPT job_dispatch.py", "QUEUE_OPTION LOCAL MAX_RUNNING 1", "ANALYSIS_LOAD RML_ENKF rml_enkf.{}".format(_lib_extension), "-- Content below originated from dummy (site_config_lines)", "JOB_SCRIPT job_dispatch_dummy.py", "QUEUE_OPTION LOCAL MAX_RUNNING 2", ], pm._site_config_lines(), )