-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from digitalaotearoa/add-poetry
Add poetry
- Loading branch information
Showing
22 changed files
with
1,762 additions
and
144 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 |
---|---|---|
@@ -1,31 +1,101 @@ | ||
name: Python | ||
|
||
on: [push] | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
types: [assigned, opened, reopened, synchronize, ready_for_review] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
tests: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Poetry | ||
run: pipx install poetry | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9.13 | ||
- name: Install OpenFisca-Aotearoa | ||
run: make install | ||
- name: Run tests | ||
run: make test | ||
pythonlint: | ||
|
||
- name: Cache tests | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
Makefile | ||
openfisca_aotearoa/tests | ||
poetry.lock | ||
tox.ini | ||
key: tests-${{ github.sha }} | ||
|
||
- name: Cache build | ||
id: cache-build | ||
uses: actions/cache@v3 | ||
with: | ||
path: dist | ||
key: build-${{ hashFiles('poetry.lock') }}-${{ github.sha }} | ||
|
||
- name: Build package | ||
if: steps.cache-build.outputs.cache-hit != 'true' | ||
run: poetry build | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: pip install --upgrade flake8 | ||
- run: flake8 | ||
yamllint: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Poetry | ||
run: pipx install poetry | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9.13 | ||
cache: poetry | ||
cache-dependency-path: poetry.lock | ||
|
||
- name: Install dependencies | ||
run: make install | ||
|
||
- name: Lint files | ||
run: make lint | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: pip install --upgrade yamllint | ||
- run: yamllint --version | ||
- name: YAML lint | ||
run: yamllint --format=github . | ||
- name: Install Tox | ||
run: pipx install tox | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9.13 | ||
|
||
- name: Restore tests | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
Makefile | ||
openfisca_aotearoa/tests | ||
poetry.lock | ||
tox.ini | ||
key: tests-${{ github.sha }} | ||
|
||
- name: Restore build | ||
uses: actions/cache@v3 | ||
with: | ||
path: dist | ||
key: build-${{ hashFiles('poetry.lock') }}-${{ github.sha }} | ||
|
||
- name: Run the test suite | ||
run: tox |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"""Smoke-test to ensure the API runs and returns a valid response.""" | ||
|
||
import json | ||
import random | ||
import subprocess | ||
from subprocess import SubprocessError, TimeoutExpired | ||
from urllib import request | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def host(): | ||
"""Return the host to use for the API.""" | ||
|
||
return "127.0.0.1" | ||
|
||
|
||
@pytest.fixture | ||
def port(): | ||
"""Return a random port to use for the API.""" | ||
|
||
return random.randint(5000, 5999) | ||
|
||
|
||
@pytest.fixture | ||
def endpoint(): | ||
"""Return the endpoint to use for the API test.""" | ||
|
||
return "spec" | ||
|
||
|
||
@pytest.fixture | ||
def timeout(): | ||
"""Return the timeout to use for the API.""" | ||
|
||
return 2.5 | ||
|
||
|
||
@pytest.fixture | ||
def payload(timeout, host, port, endpoint): | ||
"""Return the payload to use for the API test.""" | ||
|
||
return {"url": f"http://{host}:{port}/{endpoint}", "timeout": timeout} | ||
|
||
|
||
@pytest.fixture | ||
def pipe(): | ||
"""Return a descriptor to use for the server subprocess.""" | ||
|
||
return subprocess.PIPE | ||
|
||
|
||
@pytest.fixture | ||
def server(host, port, pipe, timeout): | ||
"""Return a server subprocess.""" | ||
|
||
cmd = [ | ||
"openfisca", | ||
"serve", | ||
"--country-package", | ||
"openfisca_aotearoa", | ||
"--port", | ||
str(port), | ||
] | ||
|
||
with subprocess.Popen(cmd, stdout = pipe, stderr = pipe) as proc: | ||
try: | ||
_, out = proc.communicate(timeout = timeout) | ||
|
||
except TimeoutExpired as error: | ||
if error.stderr is not None: | ||
out = error.stderr | ||
|
||
else: | ||
out = f"Timed out after {timeout}s ({proc.pid})".encode() | ||
|
||
if f"Listening at: http://{host}:{port} ({proc.pid})" in str(out): | ||
yield | ||
proc.terminate() | ||
|
||
else: | ||
proc.terminate() | ||
raise SubprocessError(f"Failed to start!\n{out.decode()}") | ||
|
||
|
||
def test_openfisca_server(server, payload): | ||
"""Test the OpenFisca API serves the /spec endpoint.""" | ||
|
||
with request.urlopen(**payload) as response: | ||
data = json.loads(response.read().decode("utf-8")) | ||
assert data["info"]["title"] == "Openfisca-Aotearoa Web API" |
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
3 changes: 1 addition & 2 deletions
3
openfisca_aotearoa/variables/acts/oranga_tamariki/interpretation/child.py
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
3 changes: 1 addition & 2 deletions
3
openfisca_aotearoa/variables/acts/social_security/interpretation/financially_independent.py
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
3 changes: 1 addition & 2 deletions
3
openfisca_aotearoa/variables/acts/social_security/interpretation/relationship.py
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
Oops, something went wrong.