Skip to content

Commit

Permalink
Playground with all command at ersilia-os#1368
Browse files Browse the repository at this point in the history
  • Loading branch information
Abellegese committed Nov 18, 2024
1 parent b189365 commit 7128fb9
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 112 deletions.
36 changes: 20 additions & 16 deletions test/playground/config.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
python_version: "3.10.10"
model_id: "eos3b5e"
model_ids: ["eos3b5e", "eos4e40", "eos7d58", "eos9gg2"]
input_file: "files/input.csv"
output_file: "files/result.csv" # "files/result.csv" & "files/output_eos9gg2_0.json" # Leave blank if you don’t need output
output_redirection: false # Enable redirection of command output to a file
max_runtime_minutes: 10 # applied for the run command only
fetch_flags: "--from_github" # Add any optional flags here; leave empty if not needed. eg --from_dockerhub
serve_flags: ""
run_flags: ""
overwrite_ersilia_repo: false # Set to true to overwrite if repo exists
use_existing_env: true
delete_model: true
activate_docker: true
runner: "single" # multiple for multiple
cli_type: "all" # cli type: fetch, serve, run, close, delete
cli_type: all
delete_model: true
fetch_flags: --from_dockerhub
input_file: files/input.csv
log_error: true
log_path: "files/error_log" # current dir for instance: no extention(.txt)
log_path: files/error_log
max_runtime_minutes: 10
model_id: eos3b5e
model_ids:
- eos3b5e
- eos4e40
- eos7d58
- eos9gg2
output_file: files/result.csv
output_redirection: false
overwrite_ersilia_repo: false
python_version: 3.10.10
run_flags: ''
runner: single
serve_flags: ''
use_existing_env: true
201 changes: 105 additions & 96 deletions test/playground/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
REPO_URL = "https://github.com/ersilia-os/ersilia.git"
REPO_DIR = Path("ersilia")


def update_yaml_values(new_values: dict):
config = yaml.safe_load(config_path.read_text())
config.update(new_values)
config_path.write_text(yaml.dump(config))
existing_config = yaml.safe_load(
config_path.read_text()
)
existing_config.update(new_values)
config_path.write_text(yaml.dump(existing_config))


def get_python_version():
return config.get("python_version", "3.10.10")

@nox.session(venv_backend="conda", python=get_python_version())
def test_cli(session):
"""Test CLI with initial and updated configurations."""

def install_dependencies(session):
session.install(
"pytest",
"pytest-asyncio",
Expand All @@ -30,23 +33,14 @@ def test_cli(session):
"rich",
)

if config.get("use_existing_env", False):
logger.info("Using existing environment, skipping setup and installation.")

session.run("ersilia", "--help", external=True)
session.run(
"pytest",
"commands.py",
"-v",
silent=False,
external=True,
def setup_ersilia(session):
if REPO_DIR.exists() and config.get(
"overwrite_ersilia_repo", False
):
logger.info(
f"Overwriting existing repository directory: {REPO_DIR}"
)
return

session.conda_install(f"python={get_python_version()}")

if REPO_DIR.exists() and config.get("overwrite_ersilia_repo", False):
logger.info(f"Overwriting existing repository directory: {REPO_DIR}")
shutil.rmtree(REPO_DIR)

if not REPO_DIR.exists():
Expand All @@ -57,91 +51,106 @@ def test_cli(session):
external=True,
)
else:
logger.info(f"Using existing repository directory: {REPO_DIR}")
logger.info(
f"Using existing repository directory: {REPO_DIR}"
)

session.chdir(REPO_DIR)
session.install("-e", ".")
session.chdir(ORIGINAL_DIR)

session.run(
"ersilia",
"--help",
external=True,

@nox.session(
venv_backend="conda", python=get_python_version()
)
def setup(session):
install_dependencies(session)
setup_ersilia(session)


@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_from_github(session):
install_dependencies(session)
logger.info(
f'CLI test for model: {config.get("model_id")} and {config.get("fetch_flags")}'
)
session.run("pytest", "commands.py", "-v", silent=False)

# default run --from_github
logger.info(f'CLI test for model: {config.get("model_id")} and {config.get("fetch_flags")}')
session.run(
"pytest",
"commands.py",
"-v",
silent=False,

@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_from_dockerhub(session):
install_dependencies(session)
update_yaml_values({"fetch_flags": "--from_dockerhub"})
logger.info(
f'CLI test for model: {config.get("model_id")} and {config.get("fetch_flags")}'
)

# default run --from_dockerhub
update_yaml_values({
"fetch_flags": "--from_dockerhub"
})

logger.info(f'CLI test for model: {config.get("model_id")} and {config.get("fetch_flags")}')
session.run(
"pytest",
"commands.py",
"-v",
silent=False
session.run("pytest", "commands.py", "-v", silent=False)


@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_auto_fetcher_decider(session):
install_dependencies(session)
update_yaml_values({"fetch_flags": ""})
logger.info(
f'CLI test for model: {config.get("model_id")} and auto fetcher decider'
)
# CLI test run for auto fetcher decider
update_yaml_values({
"fetch_flags": ""
})

logger.info(f'CLI test for model: {config.get("model_id")} and auto fetcher decider')
session.run(
"pytest",
"commands.py",
"-v",
silent=False
session.run("pytest", "commands.py", "-v", silent=False)


@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_fetch_multiple_models(session):
install_dependencies(session)
update_yaml_values(
{
"runner": "multiple",
"cli_type": "fetch",
"fetch_flags": "--from_dockerhub",
}
)

logger.info(f"Fetching and Serving Multiple Models: Fetching")
update_yaml_values({
"runner": "multiple",
"cli_type": "fetch",
"fetch_flags": "--from_dockerhub"
})

session.run(
"pytest",
"commands.py",
"-v",
silent=False
logger.info(
f"Fetching and Serving Multiple Models: Fetching"
)
session.run("pytest", "commands.py", "-v", silent=False)

logger.info(f"Fetching and Serving Multiple Models: Serving")
update_yaml_values({
"runner": "multiple",
"cli_type": "serve"
})

session.run(
"pytest",
"commands.py",
"-v",
silent=False
)

logger.info(f"Standard and Conventional Run: Conventional")
update_yaml_values({
"runner": "single",
"cli_type": "all",
"fetch_flags": "--from_dockerhub",
"output_file": "files/output_eos9gg2_0.json",
"output_redirection": "true"
})

session.run(
"pytest",
"commands.py",
"-v",
silent=False
)
@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_serve_multiple_models(session):
install_dependencies(session)
update_yaml_values(
{"runner": "multiple", "cli_type": "serve"}
)
logger.info(
f"Fetching and Serving Multiple Models: Serving"
)
session.run("pytest", "commands.py", "-v", silent=False)


@nox.session(
venv_backend="conda", python=get_python_version()
)
def test_conventional_run(session):
"""Run pytest for standard and conventional run."""
install_dependencies(session)
update_yaml_values(
{
"runner": "single",
"cli_type": "all",
"fetch_flags": "--from_dockerhub",
"output_file": "files/output_eos9gg2_0.json",
"output_redirection": "true",
}
)
logger.info(
f"Standard and Conventional Run: Conventional"
)
session.run("pytest", "commands.py", "-v", silent=False)

0 comments on commit 7128fb9

Please sign in to comment.