Skip to content

Commit

Permalink
Add snakemake test file
Browse files Browse the repository at this point in the history
  • Loading branch information
percyfal committed Jan 10, 2025
1 parent 5426f81 commit ab9e262
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions tests/test_snakemake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""Test snakemake module."""

import click

from nbis.snakemake import no_profile_option
from nbis.snakemake import profile_option
from nbis.snakemake import report_option
from nbis.snakemake import test_option


class TestProfileOption:
"""Test snakemake profile_option."""

def test_profile_option(self, runner):
"""Test profile_option."""

@click.command()
@profile_option()
def cmd(profile):
print(profile)

ret = runner.invoke(cmd, [])
assert ret.stdout == "['--profile', 'local']\n"
ret = runner.invoke(cmd, ["--profile", "test"])
assert ret.stdout == "['--profile', 'test']\n"

def test_no_profile_option(self, runner):
"""Test no_profile_option."""

@click.command()
@profile_option()
@no_profile_option()
def cmd(profile, no_profile): # pylint: disable=unused-argument
print(profile)

ret = runner.invoke(cmd, [])
assert ret.stdout == "['--profile', 'local']\n"
ret = runner.invoke(cmd, ["--no-profile"])
assert ret.stdout == "[]\n"


class TestReportOption:
"""Test snakemake report_option."""

def test_report_option(self, runner):
"""Test report_option."""

@click.command()
@report_option()
def cmd(report):
print(report)

ret = runner.invoke(cmd, [])
assert ret.stdout == "[]\n"
ret = runner.invoke(cmd, ["--report"])
assert ret.stdout == "['--report', 'report.html']\n"

def test_report_option_with_profile(self, runner):
"""Test report option with profile."""

@click.command()
@report_option(report_file="test.html")
@profile_option()
@no_profile_option()
def cmd(report, profile, no_profile): # pylint: disable=unused-argument
print(report, profile)

ret = runner.invoke(cmd, [])
assert ret.stdout == "[] ['--profile', 'local']\n"
ret = runner.invoke(cmd, ["--report"])
assert ret.stdout == "['--report', 'test.html'] []\n"


class TestTestOption:
"""Test snakemake test_option."""

def test_test_option(self, runner):
"""Test test_option."""

@click.command()
@test_option()
def cmd(test):
print(test)

ret = runner.invoke(cmd, [])
assert ret.stdout == "[]\n"
ret = runner.invoke(cmd, ["--test"])
assert ret.stdout == "['--config', '__test__=True']\n"

def test_test_option_with_config(self, runner):
"""Test test_option with config."""

@click.command()
@test_option(config=["foo=bar"])
def cmd(test):
print(test)

ret = runner.invoke(cmd, ["--test"])
assert ret.stdout == "['--config', '__test__=True', 'foo=bar']\n"

def test_test_option_with_options(self, runner):
"""Test test_option with options."""

@click.command()
@test_option(options=["--foo", "bar"])
def cmd(test):
print(test)

ret = runner.invoke(cmd, ["--test"])
assert ret.stdout == "['--foo', 'bar', '--config', '__test__=True']\n"

0 comments on commit ab9e262

Please sign in to comment.