|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import pytest |
| 4 | +import shutil |
| 5 | +import os |
| 6 | +from pathlib import Path |
| 7 | +import tempfile |
| 8 | +import time |
| 9 | + |
| 10 | +from ProConPy.config_var import ConfigVar, cvars |
| 11 | +from ProConPy.stage import Stage |
| 12 | +from ProConPy.csp_solver import csp |
| 13 | +from visualCaseGen.cime_interface import CIME_interface |
| 14 | +from visualCaseGen.initialize_configvars import initialize_configvars |
| 15 | +from visualCaseGen.initialize_widgets import initialize_widgets |
| 16 | +from visualCaseGen.initialize_stages import initialize_stages |
| 17 | +from visualCaseGen.specs.options import set_options |
| 18 | +from visualCaseGen.specs.relational_constraints import get_relational_constraints |
| 19 | +from visualCaseGen.custom_widget_types.mom6_bathy_launcher import MOM6BathyLauncher |
| 20 | +from visualCaseGen.custom_widget_types.case_creator_widget import CaseCreatorWidget |
| 21 | +from tests.utils import safe_create_case |
| 22 | + |
| 23 | + |
| 24 | +# do not show logger output |
| 25 | +import logging |
| 26 | + |
| 27 | +logger = logging.getLogger() |
| 28 | +logger.setLevel(logging.CRITICAL) |
| 29 | + |
| 30 | +base_temp_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "temp")) |
| 31 | + |
| 32 | + |
| 33 | +def test_custom_compset_std_grid(): |
| 34 | + """Configure a custom compset with a standard grid: 2000_DATM%JRA_SLND_CICE%PRES_MOM6_SROF_SGLC_WW3. Progress through the stages |
| 35 | + until the launch stage is reached.""" |
| 36 | + |
| 37 | + ConfigVar.reboot() |
| 38 | + Stage.reboot() |
| 39 | + cime = CIME_interface() |
| 40 | + initialize_configvars(cime) |
| 41 | + initialize_widgets(cime) |
| 42 | + initialize_stages(cime) |
| 43 | + set_options(cime) |
| 44 | + csp.initialize(cvars, get_relational_constraints(cvars), Stage.first()) |
| 45 | + |
| 46 | + # At initialization, the first stage should be enabled |
| 47 | + assert Stage.first().enabled |
| 48 | + cvars['COMPSET_MODE'].value = 'Custom' |
| 49 | + |
| 50 | + # CCOMPSET_MODE is the only variable in the first stage, so assigning a value to it should disable the first stage |
| 51 | + assert not Stage.first().enabled |
| 52 | + |
| 53 | + # The next stge is Custom Component Set, whose first child is Model Time Period |
| 54 | + assert Stage.active().title.startswith('Time Period') |
| 55 | + cvars['INITTIME'].value = '1850' |
| 56 | + |
| 57 | + cvars['COMP_OCN'].value = "mom" |
| 58 | + cvars['COMP_ICE'].value = "sice" |
| 59 | + cvars['COMP_ATM'].value = "cam" |
| 60 | + cvars['COMP_ROF'].value = "mosart" |
| 61 | + cvars['COMP_LND'].value = "clm" |
| 62 | + cvars['COMP_WAV'].value = "swav" |
| 63 | + cvars['COMP_GLC'].value = "sglc" |
| 64 | + |
| 65 | + |
| 66 | + assert Stage.active().title.startswith('Component Physics') |
| 67 | + |
| 68 | + cvars['COMP_ATM_PHYS'].value = "CAM60" |
| 69 | + cvars['COMP_LND_PHYS'].value = "CLM60" |
| 70 | + |
| 71 | + assert Stage.active().title.startswith('Component Options') |
| 72 | + |
| 73 | + cvars['COMP_ATM_OPTION'].value = "1PCT" |
| 74 | + cvars['COMP_LND_OPTION'].value = "BGC" |
| 75 | + cvars['COMP_OCN_OPTION'].value = "(none)" |
| 76 | + cvars['COMP_ICE_OPTION'].value = "(none)" |
| 77 | + cvars['COMP_ROF_OPTION'].value = "(none)" |
| 78 | + |
| 79 | + assert Stage.active().title.startswith('2. Grid') |
| 80 | + |
| 81 | + cvars['GRID_MODE'].value = 'Standard' |
| 82 | + cvars['GRID'].value = 'f09_t232' |
| 83 | + |
| 84 | + assert Stage.active().title.startswith('3. Launch') |
| 85 | + launch_stage = Stage.active() |
| 86 | + |
| 87 | + with tempfile.TemporaryDirectory(dir=base_temp_dir) as temp_case_path: |
| 88 | + pass # immediately remove the random temporary directory, |
| 89 | + # which will become the caseroot directory below |
| 90 | + |
| 91 | + cvars["CASEROOT"].value = temp_case_path |
| 92 | + |
| 93 | + case_creator = launch_stage._widget._main_body.children[-1] |
| 94 | + assert isinstance(case_creator, CaseCreatorWidget) |
| 95 | + |
| 96 | + cvars["PROJECT"].value = "12345" |
| 97 | + |
| 98 | + # *Click* the create_case button |
| 99 | + safe_create_case(cime.srcroot, case_creator) |
| 100 | + |
| 101 | + # sleep for a bit to allow the case to be created |
| 102 | + time.sleep(5) |
| 103 | + |
| 104 | + # remove the caseroot directory |
| 105 | + shutil.rmtree(temp_case_path) |
| 106 | + |
| 107 | + |
0 commit comments