-
Notifications
You must be signed in to change notification settings - Fork 120
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
Showing
1 changed file
with
35 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import attrs | ||
from zope.interface import Interface, implementer | ||
|
||
from twisted.trial.unittest import SynchronousTestCase | ||
|
||
from .._attrs_zope import provides | ||
|
||
|
||
class IWhatever(Interface): | ||
... | ||
|
||
|
||
@implementer(IWhatever) | ||
class YesWhatever: | ||
... | ||
|
||
|
||
class NoWhatever: | ||
... | ||
|
||
|
||
@attrs.define() | ||
class WhateverContainer: | ||
whatever: object = attrs.field(validator=provides(IWhatever)) | ||
|
||
|
||
class ProvidesTestCase(SynchronousTestCase): | ||
def test_yes(self) -> None: | ||
WhateverContainer(YesWhatever()) | ||
|
||
def test_no(self) -> None: | ||
with self.assertRaises(TypeError): | ||
WhateverContainer(NoWhatever()) |