예제 #1
0
    def test_constructors(self):
        with TestAreaContext("site_config_constructor_test") as work_area:
            work_area.copy_directory(self.snake_case_directory)
            config_file = "snake_oil/snake_oil.ert"

            ERT_SITE_CONFIG = SiteConfig.getLocation()
            ERT_SHARE_PATH = os.path.dirname(ERT_SITE_CONFIG)
            snake_config_dict = {
                ConfigKeys.INSTALL_JOB: [
                    {
                        ConfigKeys.NAME:
                        "SNAKE_OIL_SIMULATOR",
                        ConfigKeys.PATH:
                        os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_SIMULATOR",
                    },
                    {
                        ConfigKeys.NAME:
                        "SNAKE_OIL_NPV",
                        ConfigKeys.PATH:
                        os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_NPV",
                    },
                    {
                        ConfigKeys.NAME:
                        "SNAKE_OIL_DIFF",
                        ConfigKeys.PATH:
                        os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_DIFF",
                    },
                ],
                ConfigKeys.INSTALL_JOB_DIRECTORY: [
                    ERT_SHARE_PATH + "/forward-models/res",
                    ERT_SHARE_PATH + "/forward-models/shell",
                    ERT_SHARE_PATH + "/forward-models/templating",
                    ERT_SHARE_PATH + "/forward-models/old_style",
                ],
                ConfigKeys.SETENV: [
                    {
                        ConfigKeys.NAME: "SILLY_VAR",
                        ConfigKeys.VALUE: "silly-value"
                    },
                    {
                        ConfigKeys.NAME: "OPTIONAL_VAR",
                        ConfigKeys.VALUE: "optional-value",
                    },
                ],
                ConfigKeys.LICENSE_PATH:
                "some/random/path",
                ConfigKeys.UMASK:
                18,
            }

            site_config_user_file = SiteConfig(user_config_file=config_file)
            site_config_dict = SiteConfig(config_dict=snake_config_dict)
            self.assertEqual(site_config_dict, site_config_user_file)

            with self.assertRaises(ValueError):
                site_config = SiteConfig(user_config_file=config_file,
                                         config_dict=snake_config_dict)
예제 #2
0
    def test_constructors(self):
        with TestAreaContext("site_config_constructor_test") as work_area:
            work_area.copy_directory(self.snake_case_directory)
            config_file = "snake_oil/snake_oil.ert"

            ERT_SITE_CONFIG = SiteConfig.getLocation()
            ERT_SHARE_PATH = os.path.dirname(ERT_SITE_CONFIG)
            snake_config_dict = {
                "INSTALL_JOB":
                    [
                        {
                            "NAME": "SNAKE_OIL_SIMULATOR",
                            "PATH": os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_SIMULATOR"
                        },
                        {
                            "NAME": "SNAKE_OIL_NPV",
                            "PATH": os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_NPV"
                        },
                        {
                            "NAME": "SNAKE_OIL_DIFF",
                            "PATH": os.getcwd() + "/snake_oil/jobs/SNAKE_OIL_DIFF"
                        }
                    ],
                "INSTALL_JOB_DIRECTORY":
                    [
                        ERT_SHARE_PATH + '/forward-models/res',
                        ERT_SHARE_PATH + '/forward-models/shell',
                        ERT_SHARE_PATH + '/forward-models/templating',
                        ERT_SHARE_PATH + '/forward-models/old_style'
                    ],

                "SETENV":
                    [
                        {
                            "NAME": "SILLY_VAR",
                            "VALUE": "silly-value"
                        },
                        {
                            "NAME": "OPTIONAL_VAR",
                            "VALUE": "optional-value"
                        }
                    ],
                "LICENSE_PATH": "some/random/path",

                "UMASK": 18
            }

            site_config_user_file = SiteConfig(user_config_file=config_file)
            site_config_dict = SiteConfig(config_dict=snake_config_dict)
            self.assertEqual(site_config_dict, site_config_user_file)

            with self.assertRaises(ValueError):
                site_config = SiteConfig(user_config_file=config_file, config_dict=snake_config_dict)
예제 #3
0
    def test_workflow_list_constructor(self):
        with TestAreaContext("ert_workflow_list_test") as work_area:

            ERT_SITE_CONFIG = SiteConfig.getLocation()
            ERT_SHARE_PATH = os.path.dirname(ERT_SITE_CONFIG)

            self.config_dict = {
                ConfigKeys.LOAD_WORKFLOW_JOB: [{
                    ConfigKeys.NAME:
                    "print_uber",
                    ConfigKeys.PATH:
                    os.getcwd() + "/simple_config/workflows/UBER_PRINT",
                }],
                ConfigKeys.LOAD_WORKFLOW: [{
                    ConfigKeys.NAME:
                    "magic_print",
                    ConfigKeys.PATH:
                    os.getcwd() + "/simple_config/workflows/MAGIC_PRINT",
                }],
                ConfigKeys.WORKFLOW_JOB_DIRECTORY: [
                    ERT_SHARE_PATH + "/workflows/jobs/shell",
                    ERT_SHARE_PATH + "/workflows/jobs/internal/config",
                    ERT_SHARE_PATH + "/workflows/jobs/internal-gui/config",
                ],
            }

            work_area.copy_directory(self.case_directory)

            config_file = "simple_config/minimum_config"
            with open(config_file, "a+") as ert_file:
                ert_file.write(
                    "LOAD_WORKFLOW_JOB workflows/UBER_PRINT print_uber\n")
                ert_file.write(
                    "LOAD_WORKFLOW workflows/MAGIC_PRINT magic_print\n")

            os.mkdir("simple_config/workflows")

            with open("simple_config/workflows/MAGIC_PRINT", "w") as f:
                f.write("print_uber\n")
            with open("simple_config/workflows/UBER_PRINT", "w") as f:
                f.write("EXECUTABLE ls\n")

            res_config = ResConfig(config_file)
            list_from_content = res_config.ert_workflow_list
            list_from_dict = ErtWorkflowList(
                subst_list=res_config.subst_config.subst_list,
                config_dict=self.config_dict,
            )
            self.assertEqual(list_from_content, list_from_dict)