コード例 #1
0
def test_run_export_pathfile(monkeypatch):
    with ErtPluginContext():
        run_path_file = Path("output/run_path_file/.some_new_name")
        config_file = "snake_oil.ert"
        with open(config_file, encoding="utf-8", mode="a") as fout:
            fout.write(f"RUNPATH_FILE {run_path_file}\n")
        rc = ResConfig(user_config_file=config_file)
        ert = EnKFMain(rc)
        notifier = ErtCliNotifier(ert, config_file)
        with ERT.adapt(notifier):
            run_mock = MagicMock()
            run_mock.hasFailed.return_value = False
            export_mock = MagicMock()
            export_mock.hasFailed.return_value = False

            monkeypatch.setattr(
                ERT.enkf_facade,
                "get_workflow_job",
                MagicMock(side_effect=[export_mock, run_mock]),
            )
            ex = Exporter()
            parameters = {
                "output_file": "export.csv",
                "time_index": "raw",
                "column_keys": "FOPR",
            }
            ex.run_export(parameters)
            expected_call = call(
                arguments=[
                    f"{run_path_file.absolute()}", "export.csv", "raw", "FOPR"
                ],
                ert=ERT.ert,
                verbose=True,
            )
            assert export_mock.run.call_args == expected_call
コード例 #2
0
ファイル: test_exporter.py プロジェクト: oyvindeide/ert
def test_exporter_is_not_valid():
    config_file = "snake_oil.ert"
    rc = ResConfig(user_config_file=config_file)
    rc.convertToCReference(None)
    ert = EnKFMain(rc)
    ex = Exporter(ert)
    assert not ex.is_valid()
コード例 #3
0
 def __init__(self):
     super(ExportTool, self).__init__("Export Data", "tools/export",
                                      resourceIcon("ide/table_export"))
     self.__export_widget = None
     self.__dialog = None
     self.__exporter = Exporter()
     self.setEnabled(self.__exporter.is_valid())
コード例 #4
0
ファイル: test_exporter.py プロジェクト: oyvindeide/ert
def test_exporter_is_valid():
    with ErtPluginContext():
        config_file = "snake_oil.ert"
        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        ex = Exporter(ert)
        assert ex.is_valid(), "Missing CSV_EXPORT2 or EXPORT_RUNPATH jobs"
コード例 #5
0
def test_exporter_is_not_valid():
    config_file = "snake_oil.ert"
    rc = ResConfig(user_config_file=config_file)
    rc.convertToCReference(None)
    ert = EnKFMain(rc)
    notifier = ErtCliNotifier(ert, config_file)
    with ERT.adapt(notifier):
        ex = Exporter()
        assert not ex.is_valid()
コード例 #6
0
class ExportTool(Tool):
    def __init__(self):
        super(ExportTool, self).__init__("Export Data", "tools/export",
                                         resourceIcon("ide/table_export"))
        self.__export_widget = None
        self.__dialog = None
        self.__exporter = Exporter()
        self.setEnabled(self.__exporter.is_valid())

    def trigger(self):
        if self.__export_widget is None:
            self.__export_widget = ref(ExportPanel(self.parent()))
            self.__export_widget().runExport.connect(self._run_export)

        self.__dialog = ref(
            ClosableDialog("Export", self.__export_widget(), self.parent()))
        self.__export_widget().updateExportButton.connect(
            self.__dialog().toggleButton)
        self.__dialog().addButton("Export", self.export)
        self.__dialog().show()

    def _run_export(self, params):
        try:
            self.__exporter.run_export(params)
            QMessageBox.information(None, "Success", """Export completed!""",
                                    QMessageBox.Ok)
        except UserWarning as usrwarning:
            logging.error(str(usrwarning))
            QMessageBox.warning(
                None,
                "Failure",
                """Export failed with the follwing message:\n{}""".format(
                    str(usrwarning)),
                QMessageBox.Ok,
            )

    def export(self):
        self.__export_widget().export()
        self.__dialog().accept()
コード例 #7
0
ファイル: test_exporter.py プロジェクト: oyvindeide/ert
def test_run_export():
    with ErtPluginContext():
        config_file = "snake_oil.ert"
        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        ex = Exporter(ert)
        parameters = {
            "output_file": "export.csv",
            "time_index": "raw",
            "column_keys": "FOPR",
        }
        ex.run_export(parameters)

        shutil.rmtree("storage")
        with pytest.raises(UserWarning) as warn:
            ex.run_export(parameters)
        assert ex._export_job in str(warn)
コード例 #8
0
 def __init__(self, ert):
     super().__init__("Export data", "tools/export", resourceIcon("share.svg"))
     self.__export_widget = None
     self.__dialog = None
     self.__exporter = Exporter(ert)
     self.setEnabled(self.__exporter.is_valid())