Skip to content

Commit

Permalink
chore: move grpc tests into examples folder
Browse files Browse the repository at this point in the history
skip running grpc on 3.6 due to protobuf error
3.6 passing locally on macos and on cirrus cli linux
  • Loading branch information
YOU54F committed Aug 3, 2023
1 parent 8c743cd commit 47632c7
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
- python --version
- python -m pip install --upgrade pip
- python -m pip install -r requirements_dev.txt
- python -m flake8 --show-source --exclude examples/area_calculator/area_calculator_pb2.py,examples/area_calculator/area_calculator_pb2_grpc.py,.git,__pycache__,build,dist,.tox
- python -m flake8 --show-source --exclude examples/grpc/area_calculator_pb2.py,examples/grpc/area_calculator_pb2_grpc.py,.git,__pycache__,build,dist,.tox
- python -m pydocstyle pact
- python -m tox -e test
- make examples
Expand Down
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ help:
@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 " todo to run the example v3 todo tests"
@echo " grpc to run the example grpc e2e tests"
@echo " todo to run the example todo tests"
@echo " package to create a distribution package in /dist/"
@echo " release to perform a release build, including deps, test, and package targets"
@echo " test to run all tests"
Expand Down Expand Up @@ -79,11 +80,20 @@ define MESSAGING
endef
export MESSAGING

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

define TODO
echo "todo make"
cd examples/v3/todo
cd examples/todo
pip install -q -r requirements.txt
pip install -e ../../../
pip install -e ../../
./run_pytest.sh
endef
export TODO
Expand All @@ -108,13 +118,17 @@ fastapi:
messaging:
bash -c "$$MESSAGING"

.PHONY: grpc
grpc:
bash -c "$$GRPC"

.PHONY: todo
todo:
bash -c "$$TODO"


.PHONY: examples
examples: consumer flask fastapi messaging
examples: consumer flask fastapi messaging grpc
# examples: consumer flask fastapi messaging todo


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from __future__ import print_function
import argparse

import logging

import grpc
import area_calculator_pb2
import area_calculator_pb2_grpc
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import area_calculator_pb2 as area__calculator__pb2


class CalculatorStub(object):
"""Missing associated documentation comment in .proto file."""

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grpcio==1.48.2; python_version < '3.7'
grpcio==1.56.2; python_version >= '3.7'
grpcio-tools==1.48.2; python_version < '3.7'
grpcio-tools==1.56.2; python_version >= '3.7
grpcio-tools==1.56.2; python_version >= '3.7'
4 changes: 4 additions & 0 deletions examples/grpc/run_pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -o pipefail

pytest
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@
import json
import os
import pytest
from sys import path, version_info
path.insert(0, './examples/area_calculator')
from sys import version_info
if version_info < (3, 7):
try:
from area_calculator_client import get_rectangle_area # noqa: E402
from examples.grpc.area_calculator_client import get_rectangle_area
except ImportError:
print("Skipping import for Python 3.6 due to protobuf error")
else:
from area_calculator_client import get_rectangle_area # noqa: E402
from examples.grpc.area_calculator_client import get_rectangle_area

@pytest.mark.skipif(
version_info < (3, 7),
reason="https://stackoverflow.com/questions/71759248/importerror-cannot-import-name-builder-from-google-protobuf-internal")
def test_ffi_grpc_consumer():
# Setup pact for testing
m = MockServer()
PACT_FILE_DIR = './examples/pacts'
PACT_FILE_DIR = '../pacts'
pact = m.new_pact('grpc-consumer-python', 'area-calculator-provider')
message_pact = m.new_sync_message_interaction(pact, 'A gRPC calculateMulti request')
m.with_specification(pact, 5)
m.using_plugin(pact, 'protobuf', '0.3.4')

# our interaction contents
contents = {
"pact:proto": os.path.abspath('./examples/proto/area_calculator.proto'),
"pact:proto": os.path.abspath('../proto/area_calculator.proto'),
"pact:proto-service": 'Calculator/calculateOne',
"pact:content-type": 'application/protobuf',
"request": {
Expand Down
31 changes: 31 additions & 0 deletions examples/grpc/test_grpc_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from sys import version_info
from time import sleep
import pytest
from pact import VerifierV3
import subprocess
from pact.ffi.verifier import VerifyStatus

@pytest.mark.skipif(
version_info < (3, 7),
reason="https://stackoverflow.com/questions/71759248/importerror-cannot-import-name-builder-from-google-protobuf-internal")
def test_grpc_local_pact():

grpc_server_process = subprocess.Popen(['python', 'area_calculator_server.py'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, universal_newlines=True)

# grpc_server_process = subprocess.Popen(['python', 'area_calculator_server.py'],
# cwd=join(dirname(__file__), '..', '..', 'examples', 'area_calculator'),
# stdout=subprocess.PIPE,
# stderr=subprocess.STDOUT, universal_newlines=True)
sleep(3)

verifier = VerifierV3(provider="area-calculator-provider-example",
provider_base_url="tcp://127.0.0.1:37757",
)
result = verifier.verify_pacts(
sources=["../pacts/grpc-consumer-python-area-calculator-provider.json"],
)
grpc_server_process.terminate()
assert VerifyStatus(result.return_code) == VerifyStatus.SUCCESS
# TODO - Plugin success or failure not returned in logs
102 changes: 0 additions & 102 deletions examples/pacts/v4-grpc.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ httpx==0.22.0; python_version < '3.7'
httpx==0.23.3; python_version >= '3.7'
cffi>=1.14.6
pytest-httpserver==1.0.1
grpcio==1.48.2; python_version < '3.7'
grpcio==1.56.2; python_version >= '3.7'
grpcio-tools==1.48.2; python_version < '3.7'
grpcio-tools==1.56.2; python_version >= '3.7'
# grpcio==1.48.2; python_version < '3.7'
# grpcio==1.56.2; python_version >= '3.7'
# grpcio-tools==1.48.2; python_version < '3.7'
# grpcio-tools==1.56.2; python_version >= '3.7'
25 changes: 0 additions & 25 deletions tests/ffi/test_v3_verifier.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from sys import version_info
from time import sleep
import pytest
from pact import VerifierV3
import platform
from os.path import join, dirname
import subprocess
from pact.ffi.verifier import VerifyStatus
from pact.pact_exception import PactException

Expand Down Expand Up @@ -176,27 +172,6 @@ def test_local_http_v3_pact(httpserver):
)
assert VerifyStatus(result.return_code) == VerifyStatus.SUCCESS

@pytest.mark.skipif(
version_info < (3, 7),
reason="https://stackoverflow.com/questions/71759248/importerror-cannot-import-name-builder-from-google-protobuf-internal")
def test_grpc_local_pact():

grpc_server_process = subprocess.Popen(['python', 'area_calculator_server.py'],
cwd=join(dirname(__file__), '..', '..', 'examples', 'area_calculator'),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, universal_newlines=True)
sleep(3)

verifier = VerifierV3(provider="area-calculator-provider-example",
provider_base_url="tcp://127.0.0.1:37757",
)
result = verifier.verify_pacts(
sources=["./examples/pacts/v4-grpc.json"],
)
grpc_server_process.terminate()
assert VerifyStatus(result.return_code) == VerifyStatus.SUCCESS
# TODO - Plugin success or failure not returned in logs

def test_broker_consumer_version_selectors_http_v2_pact(httpserver):
body = {"name": "Mary"}
endpoint = "/alligators/Mary"
Expand Down

0 comments on commit 47632c7

Please sign in to comment.