Skip to content

Commit

Permalink
feat: add test for pyproject example (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxb2 authored May 2, 2023
1 parent 0c087ff commit dbbd1b6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/other.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tools.my_tool.parameters]
arg1 = "entirely"
opt1 = "something"
opt2 = "else"
4 changes: 4 additions & 0 deletions tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tools.my_tool.parameters]
arg1 = "stuff"
opt1 = "things"
opt2 = "nothing"
34 changes: 34 additions & 0 deletions tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,37 @@ def test_simple_example(simple_app):
assert (
result.stdout.strip() == "people nothing stuff"
), f"Unexpected output for {conf}"


def test_pyproject_example(simple_app):
def pyproject_loader(path: str) -> typer_config._typing.ConfDict:
if not path: # set a default path to read from
path = str(HERE.joinpath("pyproject.toml"))

pyproject = typer_config.loaders.toml_loader(path)
conf = pyproject["tools"]["my_tool"]["parameters"]
return conf

pyproject_callback = typer_config.conf_callback_factory(pyproject_loader)

_app = simple_app(pyproject_callback)

result = RUNNER.invoke(_app)

assert result.exit_code == 0, f"{result.stdout}"
assert result.stdout.strip() == "things nothing stuff"

result = RUNNER.invoke(_app, ["others"])

assert result.exit_code == 0, f"{result.stdout}"
assert result.stdout.strip() == "things nothing others"

result = RUNNER.invoke(_app, ["--opt1", "people"])

assert result.exit_code == 0, f"{result.stdout}"
assert result.stdout.strip() == "people nothing stuff"

result = RUNNER.invoke(_app, ["--config", str(HERE.joinpath("other.toml"))])

assert result.exit_code == 0, f"{result.stdout}"
assert result.stdout.strip() == "something else entirely"

0 comments on commit dbbd1b6

Please sign in to comment.