Skip to content

Commit

Permalink
Merge 5244063 into 1643b38
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Jul 8, 2020
2 parents 1643b38 + 5244063 commit 6e9bac1
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion reana/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,20 @@ def is_component_runnable_example(component):
return False


def does_component_need_db(component):
"""Return whether the component needs DB to run tests.
Useful to determine which components need a Postgres DB container to run the tests.
:param component: standard component name
:type component: str
:return: True/False whether the component needs DB
:rtype: bool
"""
return component in (COMPONENTS_USING_SHARED_MODULE_DB + ["reana-db"])


def construct_workflow_name(example, workflow_engine):
"""Construct suitable workflow name for given REANA example.
Expand Down Expand Up @@ -1923,6 +1937,13 @@ def python_unit_tests(component): # noqa: D301
cmd_activate_venv = "source ~/.virtualenvs/_{}/bin/activate".format(
component
)
if does_component_need_db(component):
run_command(
"docker stop reana-postgres\n"
"echo '==> [INFO] Starting DB container...' && "
"docker run --rm --name reana-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres"
)

for cmd in [
"virtualenv ~/.virtualenvs/_{}".format(component),
"{} && which python".format(cmd_activate_venv),
Expand All @@ -1934,10 +1955,21 @@ def python_unit_tests(component): # noqa: D301
" pip install . --upgrade".format(cmd_activate_venv),
"git clean -d -ff -x",
'{} && pip install ".[tests]" --upgrade'.format(cmd_activate_venv),
"{} && python setup.py test".format(cmd_activate_venv),
"{} && {} python setup.py test".format(
cmd_activate_venv,
"REANA_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://postgres:mysecretpassword@localhost/postgres"
if does_component_need_db(component)
else "",
),
"rm -rf ~/.virtualenvs/_{}".format(component),
]:
run_command(cmd, component)

if does_component_need_db(component):
run_command(
"echo '==> [INFO] Stopping DB container...' && "
"docker stop reana-postgres"
)
else:
msg = (
"Ignoring this component that does not contain"
Expand Down

0 comments on commit 6e9bac1

Please sign in to comment.