Skip to content

Commit

Permalink
test: Create test to run executable
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-gillard committed Jun 30, 2024
1 parent e620943 commit c358fa1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: pytest
name: tox

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
dist/

# Environments
.env
Expand All @@ -11,6 +12,7 @@ venv/
ENV/
env.bak/
venv.bak/
.tox/

# Output files
*.png
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ keywords=["shadow", "finder", "locator", "map"]
"Bug Tracker" = "https://github.com/bellingcat/ShadowFinder/issues"

[tool.poetry.scripts]
shadowfinder = "shadowfinder:main_entrypoint"
shadowfinder = "shadowfinder.__main__:main"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
Expand Down
3 changes: 2 additions & 1 deletion src/shadowfinder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .shadowfinder import ShadowFinder
from .cli import ShadowFinderCli

__all__ = ["ShadowFinder"]
__all__ = ["ShadowFinder", "ShadowFinderCli"]
6 changes: 3 additions & 3 deletions src/shadowfinder/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from cli import ShadowFinderCli
from . import ShadowFinderCli
import fire


def main_entrypoint():
def main():
fire.Fire(ShadowFinderCli)


if __name__ == "__main__":
main_entrypoint()
main()
33 changes: 33 additions & 0 deletions tests/test_executable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
The tests in this file test that running shadowfinder as an executable behaves
as expected.
"""
import subprocess


def test_executable_without_args():
"""Tests that running shadowfinder without any arguments returns the CLI's help string and 0 exit code."""
# GIVEN
expected = """
NAME
shadowfinder
SYNOPSIS
shadowfinder COMMAND
COMMANDS
COMMAND is one of the following:
find
Find the shadow length of an object given its height and the date and time.
find_sun
Locate a shadow based on the solar altitude angle and the date and time.
"""

# WHEN
result = subprocess.run(['shadowfinder'], capture_output=True, text=True)

# THEN
assert result.returncode == 0
assert result.stdout.strip() == expected.strip()

0 comments on commit c358fa1

Please sign in to comment.