Skip to content
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

Fix existing examples #387

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ TEST_TEMPLATE: &TEST_TEMPLATE
- python --version
# TODO: Fix lints before enabling
- echo hatch run lint
# TODO: Implement the examples to work in hatch
- echo hatch run example
- hatch run test

linux_arm64_task:
Expand Down
87 changes: 74 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ concurrency:

env:
STABLE_PYTHON_VERSION: "3.11"
PYTEST_ADDOPTS: --color=yes

jobs:
run:
test:
name: >-
Python ${{ matrix.python-version }}
on ${{ matrix.os }}
Tests py${{ matrix.python-version }} on ${{ matrix.os }}

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
Expand Down Expand Up @@ -47,15 +47,76 @@ jobs:
- name: Install Hatch
run: pip install --upgrade hatch

- # TODO: Fix lints before enabling this
name: Lint
if: matrix.python-version == env.STABLE_PYTHON_VERSION && runner.os == 'Linux'
run: echo hatch run lint
- name: Run tests
run: hatch run test

- # TODO: Implement the examples to work in hatch
name: Examples
if: matrix.python-version == env.STABLE_PYTHON_VERSION && runner.os == 'Linux'
run: echo hatch run example
- name: Upload coverage
# TODO: Configure code coverage monitoring
if: false && matrix.python-version == env.STABLE_PYTHON_VERSION && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run tests and track code coverage
run: hatch run test
example:
name: Example

runs-on: ubuntu-latest
services:
broker:
image: pactfoundation/pact-broker:latest
ports:
- "9292:9292"
env:
# Basic auth credentials for the Broker
PACT_BROKER_ALLOW_PUBLIC_READ: "true"
PACT_BROKER_BASIC_AUTH_USERNAME: pactbroker
PACT_BROKER_BASIC_AUTH_PASSWORD: pactbroker
# Database
PACT_BROKER_DATABASE_URL: sqlite:////tmp/pact_broker.sqlite

steps:
- uses: actions/checkout@v4

- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}

- name: Install Hatch
run: pip install --upgrade hatch

- name: Ensure broker is live
run: |
i=0
until curl -sSf http://localhost:9292/diagnostic/status/heartbeat; do
i=$((i+1))
if [ $i -gt 120 ]; then
echo "Broker failed to start"
exit 1
fi
sleep 1
done

- name: Examples
run: >
hatch run example --broker-url=http://pactbroker:pactbroker@localhost:9292

# TODO: Fix lints before enabling this
# lint:
# name: Lint

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.STABLE_PYTHON_VERSION }}

# - name: Install Hatch
# run: pip install --upgrade hatch

# - name: Lint
# run: hatch run lint
111 changes: 30 additions & 81 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,106 +1,55 @@
DOCS_DIR := ./docs

PROJECT := pact-python
PYTHON_MAJOR_VERSION := 3.11

sgr0 := $(shell tput sgr0)
red := $(shell tput setaf 1)
green := $(shell tput setaf 2)

help:
@echo ""
@echo " clean to clear build and distribution directories"
@echo " examples to run the example end to end tests (consumer, fastapi, flask, messaging)"
@echo " consumer to run the example consumer tests"
@echo " fastapi to run the example FastApi provider tests"
@echo " flask to run the example Flask provider tests"
@echo " messaging to run the example messaging e2e tests"
@echo " package to create a distribution package in /dist/"
@echo " package to build a wheel and sdist"
@echo " release to perform a release build, including deps, test, and package targets"
@echo " test to run all tests"
@echo ""
@echo " test to run all tests on the current python version"
@echo " test-all to run all tests on all supported python versions"
@echo " example to run the example end to end tests (requires docker)"
@echo " lint to run the lints"
@echo " ci to run test and lints"
@echo ""
@echo " help to show this help message"
@echo ""
@echo "Most of these targets are just wrappers around hatch commands."
@echo "See https://hatch.pypa.org for information to install hatch."


.PHONY: release
release: test package
release: clean test package


.PHONY: clean
clean:
hatch clean


define CONSUMER
echo "consumer make"
cd examples/consumer
pip install -q -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export CONSUMER


define FLASK_PROVIDER
echo "flask make"
cd examples/flask_provider
pip install -q -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export FLASK_PROVIDER


define FASTAPI_PROVIDER
echo "fastapi make"
cd examples/fastapi_provider
pip install -q -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export FASTAPI_PROVIDER


define MESSAGING
echo "messaging make"
cd examples/message
pip install -q -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export MESSAGING


.PHONY: consumer
consumer:
bash -c "$$CONSUMER"


.PHONY: flask
flask:
bash -c "$$FLASK_PROVIDER"
.PHONY: package
package:
hatch build


.PHONY: fastapi
fastapi:
bash -c "$$FASTAPI_PROVIDER"
.PHONY: test
test:
hatch run test
hatch run coverage report -m --fail-under=100


.PHONY: messaging
messaging:
bash -c "$$MESSAGING"
.PHONY: test-all
test-all:
hatch run test:test


.PHONY: examples
examples: consumer flask fastapi messaging
.PHONY: example
example:
hatch run example


.PHONY: package
package:
hatch build
.PHONY: lint
lint:
hatch run lint


.PHONY: test
test:
hatch run all
hatch run test:all
coverage report -m --fail-under=100
.PHONY: ci
ci: test lint
11 changes: 11 additions & 0 deletions examples/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extend = "../pyproject.toml"

ignore = [
"S101", # Forbid assert statements
"D103", # Require docstring in public function
]

[per-file-ignores]
"tests/**.py" = [
"INP001", # Forbid implicit namespaces
]
Loading