Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Apr 2, 2024
1 parent 96e12d6 commit 918563e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.parameter_types.enum import tutorial001_str_enum as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "--network" in result.output
assert "[simple|conv|lstm]" in result.output
assert "default: simple" in result.output


def test_main():
result = runner.invoke(app, ["--network", "conv"])
assert result.exit_code == 0
assert "Training neural network of type: conv" in result.output


def test_invalid_case():
result = runner.invoke(app, ["--network", "CONV"])
assert result.exit_code != 0
assert "Invalid value for '--network': 'CONV' is not one of" in result.output
assert "simple" in result.output
assert "conv" in result.output
assert "lstm" in result.output


def test_invalid_other():
result = runner.invoke(app, ["--network", "capsule"])
assert result.exit_code != 0
assert "Invalid value for '--network': 'capsule' is not one of" in result.output
assert "simple" in result.output
assert "conv" in result.output
assert "lstm" in result.output


def test_script():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.parameter_types.enum import tutorial002_str_enum as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


def test_upper():
result = runner.invoke(app, ["--network", "CONV"])
assert result.exit_code == 0
assert "Training neural network of type: conv" in result.output


def test_mix():
result = runner.invoke(app, ["--network", "LsTm"])
assert result.exit_code == 0
assert "Training neural network of type: lstm" in result.output


def test_script():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
)
assert "Usage" in result.stdout

0 comments on commit 918563e

Please sign in to comment.