Skip to content

Commit

Permalink
✅ add pair type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Nov 17, 2024
1 parent 694a78e commit c77aa09
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/data/workflow/snk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ cli:
type: bool
null_annotation:
default: null
KeyValuePair:
default: ["key", "value"]
help: A key-value pair
type: pair
enum:
choices: [a, b, c]
test:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
{"example": {"type": "list[path]"}},
{"example": [Path("1"), Path("2")]}
),
# pair type
(
{"example": ["1", "2"]},
{"example": {"type": "pair[int, int]"}},
{"example": [1, 2]}
),
# choices
(
{"example": "a"},
{"example": {"type": "str", "choices": ["a", "b"]}},
{"example": "a"}
),
# nested dictionary
(
{"example": {"nested": "1"}},
Expand Down
142 changes: 142 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# integration tests for the annotation types from the snk config, snakemake config, and the command line interface

import pytest
from .utils import dynamic_runner
from snk_cli.config import SnkConfig


@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# str
(
{"example": "1"},
{"example": {"type": "str"}},
["--example", "1"],
"{'example': '1'}"
)])
def test_str(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# int
(
{"example": "1"},
{"example": {"type": "int"}},
["--example", "1"],
"{'example': 1}"
)])
def test_int(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# float
(
{"example": "1"},
{"example": {"type": "float"}},
["--example", "1"],
"{'example': 1.0}"
)])
def test_float(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# bool
(
{"example": "1"},
{"example": {"type": "bool"}},
["--example"],
"{'example': True}"
)])
def test_bool(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# path
(
{"example": "file"},
{"example": {"type": "path"}},
["--example", "file"],
"{'example': 'file'}"
)])
def test_path(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# list
(
{"example": [1,2,3]},
{"example": {"type": "list"}},
["--example", "1", "--example", "2", "--example", "3"],
"{'example': ['1', '2', '3']}"
)])
def test_list(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

@pytest.mark.parametrize("snakemake_config,annotations,cli_args,expected", [
# pair
(
{"example": [1, 2]},
{"example": {"type": "pair"}},
["--example", "1", "2"],
"{'example': ['1', '2']}"
),
(
{"example": [1, 2]},
{"example": {"type": "pair[int, int]"}},
["--example", "1", "2"],
"{'example': [1, 2]}"
),
(
{"example": ["1", "2"]},
{"example": {"type": "pair[float, float]"}},
["--example", "1", "2"],
"{'example': [1.0, 2.0]}"
),
(
{"example": ["1", "2"]},
{"example": {"type": "pair[str, str]"}},
["--example", "1", "2"],
"{'example': ['1', '2']}"
),
(
{"example": ["1", "2"]},
{"example": {"type": "pair[str, int]"}},
["--example", "1", "2"],
"{'example': ['1', 2]}"
),
(
{"example": ["1", "2"]},
{"example": {"type": "pair[int, str]"}},
["--example", "1", "2"],
"{'example': [1, '2']}"
)
])
def test_pair(snakemake_config, annotations, cli_args, expected):
snk_config = SnkConfig(cli=annotations)
runner = dynamic_runner(snakemake_config, snk_config)
res = runner.invoke(["run"] + cli_args)
assert res.exit_code == 0, res.stderr
assert expected in res.stdout, res.stderr

0 comments on commit c77aa09

Please sign in to comment.