Skip to content

Commit 17f032f

Browse files
committed
Begin tests
1 parent 579e5e7 commit 17f032f

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

dramatiq/registry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33

44
class Registry:
5-
'''
5+
"""
66
A Registry allows defining a collection of Actors not directly bound to a Broker.
77
88
This allows your code to declar Actors before configuring a Broker.
9-
'''
9+
"""
1010
def __init__(self):
1111
self.actors = {}
1212
self.broker = None
1313

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

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

4343
def declare_actor(self, actor):
44-
'''
44+
"""
4545
Intercept when Actor class tries to register itself.
46-
'''
46+
"""
4747
if self.broker:
4848
self.broker.declare_actor(actor)
4949
else:

tests/test_registry.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import dramatiq
2+
from dramatiq.registry import Registry
3+
4+
5+
def test_registry_can_be_declared():
6+
7+
Registry()
8+
9+
10+
def test_actor_can_be_declared_on_registry():
11+
# When I have a Registry
12+
reg = Registry()
13+
14+
# Given that I've decorated a function with @registry.actor
15+
@reg.actor
16+
def add(x, y):
17+
return x + y
18+
19+
# I expect that function to become an instance of Actor
20+
assert isinstance(add, dramatiq.Actor)
21+
assert add.broker is reg
22+
assert len(reg.actors) == 1

0 commit comments

Comments
 (0)