-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pytest GitHub workflow & convert to src/ layout (#19)
* Add pre-commit hooks and run hooks on all files * Refactor project to use src/ layout * Add basic tox.ini file to test across python versions * Add pytest GitHub workflow to run tox * Update README to include poetry run tox * minor: Wrap python version in string * Improve GitHub tox workflow to target specific python version * Rename test workflow for improved readability * test: Create test to run executable * Run black on single file * build: Update tox - resolve deps w/ pyproject.toml * Update ShadowFinder import in Jupyter Notebook
- Loading branch information
1 parent
9d5bfcf
commit e5f636b
Showing
16 changed files
with
448 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: tox | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
pytest: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11", "3.12"] | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install tox | ||
- name: Run Tests | ||
run: tox run -m ${{ matrix.python-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .shadowfinder import ShadowFinder | ||
from .cli import ShadowFinderCli | ||
|
||
__all__ = ["ShadowFinder", "ShadowFinderCli"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from . import ShadowFinderCli | ||
import fire | ||
|
||
|
||
def main(): | ||
fire.Fire(ShadowFinderCli) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import datetime | ||
|
||
from shadowfinder import ShadowFinder | ||
|
||
|
||
def test_creation_with_valid_arguments_should_pass(): | ||
"""Baseline test to assert that we can create an instance of ShadowFinder with only object height, shadow length, | ||
and a datetime object.""" | ||
# GIVEN | ||
object_height = 6 | ||
shadow_length = 3.2 | ||
date_time = datetime.now() | ||
|
||
# WHEN / THEN | ||
ShadowFinder( | ||
object_height=object_height, shadow_length=shadow_length, date_time=date_time | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[tox] | ||
envlist = py39, py310, py311, py312 | ||
labels = | ||
; Used to map GitHub workflow python version to tox env | ||
3.9 = py39 | ||
3.10 = py310 | ||
3.11 = py311 | ||
3.12 = py312 | ||
|
||
[testenv] | ||
deps = | ||
pytest>=8 | ||
commands = | ||
pytest tests/ --import-mode=importlib |