Merge pull request 'templates: add python-project' (#10) from python-template into main
This commit is contained in:
10
templates/python-project/tests/conftest.py
Normal file
10
templates/python-project/tests/conftest.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# returns a temporary directory with a fake git repo
|
||||
@pytest.fixture()
|
||||
def git_repo_path(tmp_path):
|
||||
subprocess.run(["mkdir", ".git"], cwd=tmp_path)
|
||||
return tmp_path
|
||||
16
templates/python-project/tests/test_cli.py
Normal file
16
templates/python-project/tests/test_cli.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
|
||||
import my_tool
|
||||
|
||||
|
||||
def test_no_args(capsys):
|
||||
my_tool.my_cli()
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.startswith("usage:")
|
||||
|
||||
|
||||
def test_version(capsys, monkeypatch):
|
||||
monkeypatch.setattr(sys, "argv", ["", "--version"])
|
||||
my_tool.my_cli()
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.startswith("Version:")
|
||||
16
templates/python-project/tests/test_detect_git_repo.py
Normal file
16
templates/python-project/tests/test_detect_git_repo.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import tempfile
|
||||
|
||||
import my_lib
|
||||
|
||||
|
||||
# using the fixture from conftest.py
|
||||
def test_is_git_repo(git_repo_path: str):
|
||||
result = my_lib.detect_git_repo(git_repo_path)
|
||||
assert result is True
|
||||
|
||||
|
||||
# using the fixture from conftest.py
|
||||
def test_is_not_git_repo():
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
result = my_lib.detect_git_repo(tempdir)
|
||||
assert result is False
|
||||
Reference in New Issue
Block a user