Skip to content

Commit

Permalink
Moved the test_env argument definition to a function in the new utils…
Browse files Browse the repository at this point in the history
….py module.
  • Loading branch information
rbovill committed Oct 30, 2023
1 parent dc6827b commit 2dba287
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
1 change: 1 addition & 0 deletions python/lsst/ts/IntegrationTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@
from .obssys_standby_disabled import *
from .script_queue_controller import *
from .testutils import *
from .utils import *
from .yaml_test_strings import *
25 changes: 4 additions & 21 deletions python/lsst/ts/IntegrationTests/obssys_disabled_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

__all__ = ["ObsSysDisabledEnabled", "run_obssys_disabled_enabled"]

import argparse
import asyncio

import yaml
from lsst.ts.IntegrationTests import BaseScript

from .configs.config_registry import registry
from .utils import get_test_env_arg


class ObsSysDisabledEnabled(BaseScript):
Expand Down Expand Up @@ -60,30 +60,13 @@ def __init__(self, test_env: str) -> None:


def run_obssys_disabled_enabled() -> None:
# Define the script arguments.
parser = argparse.ArgumentParser()
parser.add_argument(
"test_env",
nargs="?",
type=str.lower,
choices=["bts", "tts", "summit"],
help="Specify on which environment the tests are running (case insensitive).",
)
args = parser.parse_args()
# Print the help if the environment is not defined.
if not (args.test_env):
parser.print_help()
exit()
main(args)


def main(opts: argparse.Namespace) -> None:
# Ensure the invocation is correct.
# If not, raise KeyError.
# If it is correct, execute the state transition.
args = get_test_env_arg()
try:
script_class = ObsSysDisabledEnabled(
test_env=opts.test_env,
test_env=args.test_env,
)
except KeyError as ke:
print(repr(ke))
Expand All @@ -92,7 +75,7 @@ def main(opts: argparse.Namespace) -> None:
print(
f"\nObsSys Disabled to Enabled; "
f"running {num_scripts} scripts "
f"on the '{opts.test_env}' environment, "
f"on the '{args.test_env}' environment, "
f"with this configuration: \n"
f"{script_class.configs}"
)
Expand Down
25 changes: 4 additions & 21 deletions python/lsst/ts/IntegrationTests/obssys_standby_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

__all__ = ["ObsSysStandbyDisabled", "run_obssys_standby_disabled"]

import argparse
import asyncio

import yaml
from lsst.ts.IntegrationTests import BaseScript

from .configs.config_registry import registry
from .utils import get_test_env_arg


class ObsSysStandbyDisabled(BaseScript):
Expand Down Expand Up @@ -60,30 +60,13 @@ def __init__(self, test_env: str) -> None:


def run_obssys_standby_disabled() -> None:
# Define the script arguments.
parser = argparse.ArgumentParser()
parser.add_argument(
"test_env",
nargs="?",
type=str.lower,
choices=["bts", "tts", "summit"],
help="Specify on which environment the tests are running (case insensitive).",
)
args = parser.parse_args()
# Print the help if the environment is not defined.
if not (args.test_env):
parser.print_help()
exit()
main(args)


def main(opts: argparse.Namespace) -> None:
# Ensure the invocation is correct.
# If not, raise KeyError.
# If it is correct, execute the state transition.
args = get_test_env_arg()
try:
script_class = ObsSysStandbyDisabled(
test_env=opts.test_env,
test_env=args.test_env,
)
except KeyError as ke:
print(repr(ke))
Expand All @@ -92,7 +75,7 @@ def main(opts: argparse.Namespace) -> None:
print(
f"\nObsSys Standby to Disabled; "
f"running {num_scripts} scripts "
f"on the '{opts.test_env}' environment. "
f"on the '{args.test_env}' environment. "
f"with this configuration: \n"
f"{script_class.configs}"
)
Expand Down
41 changes: 41 additions & 0 deletions python/lsst/ts/IntegrationTests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of ts_IntegrationTests.
#
# Developed for the Vera C. Rubin Observatory Telescope & Site Software system.
# This product includes software developed by the Vera C. Rubin Observatory
# Project (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# 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

import argparse


def get_test_env_arg() -> None:
# Define the script arguments.
parser = argparse.ArgumentParser()
parser.add_argument(
"test_env",
nargs="?",
type=str.lower,
choices=["bts", "tts", "summit"],
help="Specify on which environment the tests are running (case insensitive).",
)
args = parser.parse_args()
# Print the help if the environment is not defined.
if not (args.test_env):
parser.print_help()
exit()
return args

0 comments on commit 2dba287

Please sign in to comment.