-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use __init__subclass__ instead of a metaclass for service registration
This syntax is a lot nicer and even makes adding keyword arguments really easy.
- Loading branch information
Showing
2 changed files
with
32 additions
and
17 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,21 @@ | ||
import mock | ||
|
||
from server.core import Service | ||
|
||
|
||
def test_service_registry(): | ||
with mock.patch("server.core.service.service_registry", {}) as registry: | ||
class Foo(Service): | ||
pass | ||
|
||
assert registry["foo"] is Foo | ||
assert registry == {"foo": Foo} | ||
|
||
|
||
def test_service_registry_name_override(): | ||
with mock.patch("server.core.service.service_registry", {}) as registry: | ||
class Foo(Service, name="FooService"): | ||
pass | ||
|
||
assert registry["FooService"] is Foo | ||
assert registry == {"FooService": Foo} |