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

Add a nox option to run tests as a backend group and docstring walkthough for understanding #42

Merged
merged 10 commits into from
Sep 1, 2022
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
47 changes: 40 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,77 @@ def test(session: nox_poetry.Session):
)


@nox_poetry.session(python="3.8")
@nox_poetry.session(python=["3.9"])
def devtest(session: nox_poetry.Session):
session.run_always("poetry", "install", "-E", "all", external=True)
session.run(
"pytest",
"-vv",
"--cov=sending",
"tests/test_inmemory_backend.py",
env={"SENDING__ENABLE_LOGGING": "True"},
)
session.run(
"pytest",
"-vv",
"--cov=sending",
"tests/test_jupyter_backend.py",
env={"SENDING__ENABLE_LOGGING": "True"},
)
session.run(
"pytest",
"-vv",
"--cov=sending",
"tests/test_redis_backend.py",
env={"SENDING__ENABLE_LOGGING": "True"},
)
session.run(
"pytest",
"-vv",
"--cov=sending",
"tests/test_websocket_backend.py",
env={"SENDING__ENABLE_LOGGING": "True"},
)


@nox_poetry.session(python="3.9")
def lint(session: nox_poetry.Session):
session.notify("black_check")
session.notify("flake8")
session.notify("isort_check")


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def flake8(session: nox_poetry.Session):
session.install("flake8")
session.run("flake8", *LINT_PATHS, "--count", "--show-source", "--statistics", "--benchmark")


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def black_check(session: nox_poetry.Session):
session.install("black")
session.run("black", "--check", *LINT_PATHS)


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def isort_check(session: nox_poetry.Session):
session.install("isort")
session.run("isort", "--diff", "--check", *LINT_PATHS)


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def blacken(session: nox_poetry.Session):
session.install("black")
session.run("black", *LINT_PATHS)


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def isort_apply(session: nox_poetry.Session):
session.install("isort")
session.run("isort", *LINT_PATHS)


@nox_poetry.session(python="3.8")
@nox_poetry.session(python="3.9")
def generate_coverage_xml(session: nox_poetry.Session):
session.install("coverage[toml]")
session.run("coverage", "xml")
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sending/backends/memory.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
"""A Publish Subscribe Manager which operates in memory."""
import asyncio

from ..base import AbstractPubSubManager, QueuedMessage


class InMemoryPubSubManager(AbstractPubSubManager):
"""A Publish Subscribe Manager which operates in memory."""

def __init__(self):
super().__init__()
self.message_queue: asyncio.Queue[QueuedMessage] = None

async def initialize(self, *args, **kwargs):
"""Intialize the message queue and its size."""
queue_size = kwargs.get("queue_size", 0)
self.message_queue = asyncio.Queue(queue_size)
return await super().initialize(*args, **kwargs)

async def shutdown(self, now=False):
"""Shutdown the manager with a default graceful cleanup (now=False)."""
await super().shutdown(now=now)
self.message_queue = None

Expand Down
5 changes: 5 additions & 0 deletions sending/backends/redis.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
"""A Publish Subscribe Manager which operates using Redis."""
import aioredis

from ..base import AbstractPubSubManager, QueuedMessage


class RedisPubSubManager(AbstractPubSubManager):
"""A Publish Subscribe Manager which operates using Redis."""

def __init__(self, dsn: str):
super().__init__()
self._dsn = dsn

async def initialize(self, *args, **kwargs):
"""Initialize the redis db and the pubsub manager."""
self._redis = aioredis.from_url(self._dsn)
self._redis_pubsub = self._redis.pubsub(ignore_subscribe_messages=True)
return await super().initialize(*args, **kwargs)

async def shutdown(self, now=False):
"""Shutdown the pubsub manager and redis connection."""
await super().shutdown(now=now)
await self._redis.close()
self._redis = None
Expand Down
Loading