forked from airtai/faststream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
194cbeb
commit 63eb355
Showing
16 changed files
with
112 additions
and
32 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
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,38 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
args: ["--profile", "black", "--filter-files"] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 23.3.0 | ||
hooks: | ||
- id: black | ||
|
||
# - repo: https://github.com/astral-sh/ruff-pre-commit | ||
# # Ruff version. | ||
# rev: v0.0.286 | ||
# hooks: | ||
# - id: ruff | ||
|
||
- repo: local | ||
hooks: | ||
- id: mypy | ||
name: mypy | ||
entry: "scripts/run_mypy.sh" | ||
language: python | ||
language_version: python3.8 | ||
types: [python] | ||
require_serial: true | ||
verbose: true |
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
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,25 +1,28 @@ | ||
import asyncio | ||
from pydantic import BaseModel, Field, NonNegativeFloat | ||
|
||
from faststream import FastStream, Logger | ||
from faststream.kafka import KafkaBroker | ||
|
||
|
||
class Data(BaseModel): | ||
data: NonNegativeFloat = Field( | ||
..., examples=[0.5], description="Float data example" | ||
) | ||
|
||
|
||
broker = KafkaBroker("localhost:9092") | ||
app = FastStream(broker) | ||
|
||
|
||
@broker.publisher("intermediate_data") | ||
@broker.subscriber("input_data") | ||
async def on_input_data(msg: Data, logger: Logger) -> Data: | ||
logger.info(msg) | ||
return Data(data=msg.data+1.0) | ||
return Data(data=msg.data + 1.0) | ||
|
||
|
||
@broker.publisher("output_data") | ||
@broker.subscriber("intermediate_data") | ||
async def on_intermediate(msg: Data, logger: Logger) -> Data: | ||
logger.info(msg) | ||
return Data(data=msg.data*2.0) | ||
return Data(data=msg.data * 2.0) |
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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import pytest | ||
|
||
from docs_src.kafka.base_example.app_chain import Data, broker | ||
from faststream.kafka import TestKafkaBroker | ||
from docs_src.kafka.base_example.app_chain import ( | ||
Data, | ||
broker, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_end_to_end(): | ||
|
||
@broker.subscriber("output_data") | ||
async def on_output_data(msg: Data): | ||
pass | ||
|
||
async with TestKafkaBroker(broker) as tester: | ||
await tester.publish(Data(data=0.2), "input_data") | ||
on_output_data.mock.assert_called_once_with({"data": 2.4}) | ||
on_output_data.mock.assert_called_once_with({"data": 2.4}) |
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
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,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# from: https://jaredkhan.com/blog/mypy-pre-commit | ||
|
||
# A script for running mypy, | ||
# with all its dependencies installed. | ||
|
||
set -o errexit | ||
|
||
# Change directory to the project root directory. | ||
echo "$(dirname "$0")"/.. | ||
cd "$(dirname "$0")"/.. | ||
|
||
# Install the dependencies into the mypy env. | ||
# Note that this can take seconds to run. | ||
# In my case, I need to use a custom index URL. | ||
# Avoid pip spending time quietly retrying since | ||
# likely cause of failure is lack of VPN connection. | ||
pip install --editable ".[dev]" \ | ||
--retries 1 \ | ||
--no-input \ | ||
--quiet | ||
|
||
# Run on all files, | ||
# ignoring the paths passed to this script, | ||
# so as not to miss type errors. | ||
# My repo makes use of namespace packages. | ||
# Use the namespace-packages flag | ||
# and specify the package to run on explicitly. | ||
# Note that we do not use --ignore-missing-imports, | ||
# as this can give us false confidence in our results. | ||
mypy faststream |
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