Skip to content

Commit

Permalink
Begin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
funkybob committed Jul 14, 2020
1 parent 579e5e7 commit 17f032f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dramatiq/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@


class Registry:
'''
"""
A Registry allows defining a collection of Actors not directly bound to a Broker.
This allows your code to declar Actors before configuring a Broker.
'''
"""
def __init__(self):
self.actors = {}
self.broker = None

def actor(self, fn=None, *, actor_class=Actor, actor_name=None, queue_name="default", priority=0, **options):
'''
"""
Mimics `actor.actor` decorator, but skips the actor options check, and passes `self` as broker.
'''
"""

def decorator(fn):
if not _queue_name_re.fullmatch(queue_name):
Expand All @@ -41,9 +41,9 @@ def __getattr__(self, name):
return getattr(self.broker, name)

def declare_actor(self, actor):
'''
"""
Intercept when Actor class tries to register itself.
'''
"""
if self.broker:
self.broker.declare_actor(actor)
else:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import dramatiq
from dramatiq.registry import Registry


def test_registry_can_be_declared():

Registry()


def test_actor_can_be_declared_on_registry():
# When I have a Registry
reg = Registry()

# Given that I've decorated a function with @registry.actor
@reg.actor
def add(x, y):
return x + y

# I expect that function to become an instance of Actor
assert isinstance(add, dramatiq.Actor)
assert add.broker is reg
assert len(reg.actors) == 1

0 comments on commit 17f032f

Please sign in to comment.