def test_options(simple_parser): """It is a substitute for an optparse options object.""" options = Options(parser=simple_parser) opts = options(a=1, b=True) # we can access options as attributes assert opts.a == 1 assert opts.b is True # defaults are automatically substituted assert opts.c == 'C' # get-like syntax should work assert opts.get('d', 42) == 42 # invalid keys result in KeyErrors with pytest.raises(KeyError): opts.d with pytest.raises(KeyError): opts(d=1) # just for fun we can still use dict syntax assert opts['a'] == 1
""" # validate / standardise the list of workflow states opts.states = set(opts.states.split(',')) if 'all' in opts.states: opts.states = FLOW_STATES elif (not opts.states or not all(state in FLOW_STATES for state in opts.states)): raise UserInputError( '--states must be set to a comma separated list of workflow' ' states. \nSee `cylc scan --help` for a list of supported' ' states.') if not color: # we cannot support colour or have been requested not to use it opts.colour_blind = True # print state totals key as needed if opts.format == 'rich' and not opts.colour_blind: cprint(state_totals_key() + '\n') await scanner(opts, write, scan_dir) @cli_function(get_option_parser) def cli(_, opts, color): """Implement `cylc scan`.""" asyncio.run(main(opts, color)) ScanOptions = Options(get_option_parser())
# bit of refactoring because option clashes are handled bass-ackwards # ("overrides" are added before standard options). parser.add_std_options() return parser # options we cannot simply extract from the parser DEFAULT_OPTS = { 'debug': False, 'verbose': False, 'templatevars': None, 'templatevars_file': None } RunOptions = Options(get_option_parser(add_std_opts=True), DEFAULT_OPTS) def _open_logs(id_, no_detach): """Open Cylc log handlers for a flow run.""" if not no_detach: while LOG.handlers: LOG.handlers[0].close() LOG.removeHandler(LOG.handlers[0]) log_path = get_workflow_run_log_name(id_) LOG.addHandler(TimestampRotatingFileHandler(log_path, no_detach)) # Add file installation log file_install_log_path = get_workflow_file_install_log_name(id_) RSYNC_LOG.addHandler( TimestampRotatingFileHandler(file_install_log_path, no_detach))
# bit of refactoring because option clashes are handled bass-ackwards # ("overrides" are added before standard options). parser.add_std_options() return parser # options we cannot simply extract from the parser DEFAULT_OPTS = { 'debug': False, 'verbose': False, 'templatevars': None, 'templatevars_file': None } RunOptions = Options(get_option_parser(is_restart=False, add_std_opts=True), DEFAULT_OPTS) RestartOptions = Options(get_option_parser(is_restart=True, add_std_opts=True), DEFAULT_OPTS) def _auto_register(): """Register a suite installed in the cylc-run directory.""" try: reg = suite_files.register() except SuiteServiceFileError as exc: sys.exit(exc) # Replace this process with "cylc run REG ..." for 'ps -f'. os.execv(sys.argv[0], [sys.argv[0]] + [reg] + sys.argv[1:]) def _open_logs(reg, no_detach):
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Test logic in cylc-release script.""" import pytest from typing import Any, Iterable, Optional, Tuple, Type from cylc.flow.exceptions import UserInputError from cylc.flow.option_parsers import Options from cylc.flow.scripts.release import get_option_parser, _validate Opts = Options(get_option_parser()) @pytest.mark.parametrize('opts, task_globs, expected_err', [ (Opts(), ['*'], None), (Opts(release_all=True), [], None), (Opts(release_all=True), ['*'], (UserInputError, "Cannot combine --all with TASK_GLOB")), (Opts(), [], (UserInputError, "Missing arguments: TASK_GLOB")), ]) def test_validate(opts: Options, task_globs: Iterable[str], expected_err: Optional[Tuple[Type[Exception], str]]): if expected_err: err, msg = expected_err with pytest.raises(err) as exc:
action="store", default="live", dest="run_mode", choices=['live', 'dummy', 'dummy-local', 'simulation']) parser.add_cylc_rose_options() parser.set_defaults(is_validate=True) return parser ValidateOptions = Options( get_option_parser(), # defaults { 'check_circular': False, 'profile_mode': False, 'run_mode': 'live' }) @cli_function(get_option_parser) def main(parser: COP, options: 'Values', reg: str) -> None: """cylc validate CLI.""" profiler = Profiler(None, options.profile_mode) profiler.start() if cylc.flow.flags.verbosity < 2: # for readability omit timestamps from logging unless in debug mode for handler in LOG.handlers: if isinstance(handler.formatter, CylcLogFormatter):
from cylc.flow.exceptions import ( CylcError, ServiceFileError, TaskRemoteMgmtError, WorkflowFilesError ) from cylc.flow.scripts.clean import get_option_parser as _clean_GOP from cylc.flow.workflow_files import ( WorkflowFiles, check_flow_file, check_nested_run_dirs, get_workflow_source_dir, reinstall_workflow, search_install_source_dirs) CleanOpts = Options(_clean_GOP()) @pytest.mark.parametrize( 'path, expected', [('a/b/c', '/mock_cylc_dir/a/b/c'), ('/a/b/c', '/a/b/c')] ) def test_get_cylc_run_abs_path( path: str, expected: str, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', '/mock_cylc_dir') assert workflow_files.get_cylc_run_abs_path(path) == expected