-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pytest GitHub workflow & convert to src/ layout #19
Changes from 13 commits
b9ad334
cc6519c
4187a2e
57357a8
ef1de60
33c6dc4
1c8bf71
94dd4fa
e620943
c358fa1
33a45c0
8c5f755
307cc2c
ad92a31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,18 @@ repos: | |
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- repo: https://github.com/psf/black | ||
rev: 24.2.0 | ||
|
||
- repo: local | ||
hooks: | ||
- id: black | ||
name: black | ||
entry: poetry run black | ||
language: system | ||
types: [ python ] | ||
|
||
- id: poetry-lock | ||
name: poetry lock | ||
entry: poetry lock --no-update | ||
language: system | ||
types: [yaml] | ||
files: ^pyproject\.toml$ | ||
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hook keeps the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ pip install shadowfinder | |
If you want to use ShadowFinder directly from Python, the usage is as follows. | ||
|
||
```python | ||
from shadowfinder.shadowfinder import ShadowFinder | ||
from shadowfinder import ShadowFinder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, I assume this will require updating the import in the notebook too - is that right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good eye. Updated the import in |
||
|
||
finder = ShadowFinder() | ||
|
||
|
@@ -111,7 +111,10 @@ poetry run pre-commit install | |
# Run the tool | ||
poetry run shadowfinder --help | ||
|
||
# After making changes, format your code with black: | ||
poetry run black ./ | ||
# Run tests against your current Python interpreter | ||
poetry run pytest | ||
|
||
# Or, run pytest against all shadowfinder supported Python versions | ||
poetry run tox p # p=run in parallel | ||
``` | ||
</details> |
Large diffs are not rendered by default.
This file was deleted.
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"] | ||
GalenReich marked this conversation as resolved.
Show resolved
Hide resolved
|
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() |
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() |
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 | ||
) |
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 | ||
GalenReich marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instructs
pre-commit
to use the local versions of hooks. It guarantees that the version ofblack
thats run ongit commit
matches whats in Poetry's lock file.