Skip to content

Commit

Permalink
Merge pull request #18 from trappitsch/cli_test
Browse files Browse the repository at this point in the history
Unit test for CLI `cowsay`
  • Loading branch information
trappitsch authored Feb 26, 2024
2 parents 1b0e2fe + 7df1b1b commit f763f95
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dev-dependencies = [
"pytest-cov>=4.1.0",
"pytest-mock>=3.12.0",
"gitpython>=3.1.42",
"build>=1.0.3",
]

[tool.rye.scripts]
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# with-sources: false

-e file:.
build==1.0.3
click==8.1.7
# via box
# via rich-click
Expand All @@ -25,11 +26,14 @@ markdown-it-py==3.0.0
mdurl==0.1.2
# via markdown-it-py
packaging==23.2
# via build
# via pytest
pluggy==1.4.0
# via pytest
pygments==2.17.2
# via rich
pyproject-hooks==1.0.0
# via build
pytest==8.0.0
# via pytest-cov
# via pytest-mock
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/test_cowsay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Build the `cowsay` project with PyApp.

import os
from pathlib import Path

from click.testing import CliRunner
from git import Repo
import pytest

from box.cli import cli


GIT_URL = "https://github.com/VaasuDevanS/cowsay-python.git" # repo for qtcowsay
COMMIT_HASH = "3db622cefd8b11620ece7386d4151b5e734b078b" # commit hash for v6.1


@pytest.mark.unit
def test_gui_build():
"""Build the `qtcowsay` project with PyApp."""
runner = CliRunner()
with runner.isolated_filesystem():
# app expected
app_expected = Path("target/release/cowsay")
if os.name == "nt": # on windows with have an .exe!
app_expected = app_expected.with_suffix(".exe")

# clone the repo
repo = Repo.clone_from(GIT_URL, ".")
repo.git.checkout(COMMIT_HASH) # prevent repo-jacking

# init and build
runner.invoke(cli, ["init", "-q", "-b", "build"])
result = runner.invoke(cli, ["package"])

# check result
assert result.exit_code == 0
assert "Project successfully packaged" in result.output
assert app_expected.exists()

0 comments on commit f763f95

Please sign in to comment.