Skip to content

Commit

Permalink
Add type annotations to training material tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Oct 28, 2022
1 parent 129405d commit 008f978
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
2 changes: 2 additions & 0 deletions planemo/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def cache_download(self, url, destination):
class PlanemoContext(PlanemoContextInterface):
"""Implementation of ``PlanemoContextInterface``"""

planemo_directory: Optional[str]

def __init__(self) -> None:
"""Construct a Context object using execution environment."""
self.home = os.getcwd()
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ max-complexity = 14
exclude=.eggs,.git,.tox,.venv,.venv3,build,docs/conf.py,docs/standards,project_templates/cwl_draft3_spec/

[mypy]
exclude = tests/data/
ignore_missing_imports = True
15 changes: 8 additions & 7 deletions tests/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@
}


def test_training_init():
def test_training_init() -> None:
"""Test :func:`planemo.training.Training.init`."""
train = Training(KWDS)
assert train.topics_dir == "topics"
assert train.topic is not None
assert train.tuto is None


def test_training_init_training():
def test_training_init_training() -> None:
"""Test :func:`planemo.training.Training.init_training`."""
train = Training(KWDS)
# new topic, nothing else
Expand Down Expand Up @@ -152,13 +152,13 @@ def test_training_init_training():
shutil.rmtree("metadata")


def create_existing_tutorial(exit_tuto_name, tuto_fp, topic):
def create_existing_tutorial(exit_tuto_name, tuto_fp, topic) -> None:
exist_tuto_dir = os.path.join(topic.dir, "tutorials", exit_tuto_name)
os.makedirs(exist_tuto_dir)
shutil.copyfile(tuto_fp, os.path.join(exist_tuto_dir, "tutorial.md"))


def test_training_check_topic_init_tuto():
def test_training_check_topic_init_tuto() -> None:
"""Test :func:`planemo.training.Training.check_topic_init_tuto`."""
train = Training(KWDS)
# no topic
Expand All @@ -181,7 +181,7 @@ def test_training_check_topic_init_tuto():
shutil.rmtree("metadata")


def test_fill_data_library():
def test_fill_data_library() -> None:
"""Test :func:`planemo.training.fill_data_library`."""
train = Training(KWDS)
train.kwds["tutorial_name"] = None
Expand All @@ -208,6 +208,7 @@ def test_fill_data_library():
train.kwds["zenodo_link"] = new_z_link
train.tuto = None
train.fill_data_library(CTX)
assert train.tuto
with open(train.tuto.data_lib_fp) as fh:
assert "DOI: 10.5281/zenodo.1324204" in fh.read()
with open(train.tuto.tuto_fp) as fh:
Expand All @@ -225,7 +226,7 @@ def test_fill_data_library():


@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_generate_tuto_from_wf():
def test_generate_tuto_from_wf() -> None:
"""Test :func:`planemo.training.generate_tuto_from_wf`."""
train = Training(KWDS)
train.kwds["tutorial_name"] = None
Expand Down Expand Up @@ -253,7 +254,7 @@ def test_generate_tuto_from_wf():
shutil.rmtree("metadata")


def assert_file_contains(file, text):
def assert_file_contains(file: str, text: str) -> None:
with open(file) as fh:
contents = fh.read()
if text not in contents:
Expand Down
22 changes: 11 additions & 11 deletions tests/test_training_tool_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
tool_inp_desc = tool_desc["inputs"]


def test_get_input_tool_name():
def test_get_input_tool_name() -> None:
"""Test :func:`planemo.training.tool_input.get_input_tool_name`."""
assert "Input dataset" in get_input_tool_name("1", wf_steps)
assert "output of" in get_input_tool_name("4", wf_steps)
assert get_input_tool_name("10", wf_steps) == ""


def test_get_empty_input():
def test_get_empty_input() -> None:
"""Test :func:`planemo.training.tool_input.get_empty_input`."""
assert '{% icon param-file %} *"Input file"*: File' in get_empty_input()


def test_get_empty_param():
def test_get_empty_param() -> None:
"""Test :func:`planemo.training.tool_input.get_empty_param`."""
assert '*"Parameter"*: `a value`' in get_empty_param()


def test_ToolInput_init():
def test_ToolInput_init() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.init`."""
# test type exception
with pytest.raises(Exception, match="No type for the parameter t"):
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_ToolInput_init():
assert tool_input.wf_param_values == "workdb.sqlite"


def test_ToolInput_get_formatted_inputs():
def test_ToolInput_get_formatted_inputs() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_inputs`."""
# test no input
tool_input = ToolInput(
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_ToolInput_get_formatted_inputs():
assert "(Input dataset)" in inputlist


def test_ToolInput_get_lower_param_desc():
def test_ToolInput_get_lower_param_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_lower_param_desc`."""
tool_input = ToolInput(
tool_inp_desc=tool_inp_desc[1],
Expand All @@ -139,7 +139,7 @@ def test_ToolInput_get_lower_param_desc():
assert "> - {% icon param-collection %}" in sub_param_desc


def test_ToolInput_get_formatted_section_desc():
def test_ToolInput_get_formatted_section_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_section_desc`."""
tool_input = ToolInput(
tool_inp_desc=tool_inp_desc[1],
Expand All @@ -154,7 +154,7 @@ def test_ToolInput_get_formatted_section_desc():
assert "> - {%" in section_paramlist


def test_ToolInput_get_formatted_conditional_desc():
def test_ToolInput_get_formatted_conditional_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_conditional_desc`."""
tool_input = ToolInput(
tool_inp_desc=tool_inp_desc[5],
Expand All @@ -170,7 +170,7 @@ def test_ToolInput_get_formatted_conditional_desc():
assert '> - *"' in conditional_paramlist


def test_ToolInput_get_formatted_repeat_desc():
def test_ToolInput_get_formatted_repeat_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_repeat_desc`."""
tool_input = ToolInput(
tool_inp_desc=tool_inp_desc[2],
Expand All @@ -186,7 +186,7 @@ def test_ToolInput_get_formatted_repeat_desc():
assert "> -" in repeat_desc


def test_ToolInput_get_formatted_other_param_desc():
def test_ToolInput_get_formatted_other_param_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_other_param_desc`."""
# test default value of the tool
tool_input = ToolInput(
Expand Down Expand Up @@ -232,7 +232,7 @@ def test_ToolInput_get_formatted_other_param_desc():
assert "*: ``" in tool_input.get_formatted_other_param_desc()


def test_ToolInput_get_formatted_desc():
def test_ToolInput_get_formatted_desc() -> None:
"""Test :func:`planemo.training.tool_input.ToolInput.get_formatted_desc`."""
# test no param values
tool_input = ToolInput(
Expand Down
Loading

0 comments on commit 008f978

Please sign in to comment.