docstring/test for OneToOne.unique alternate constructor

This commit is contained in:
Mahmoud Hashemi 2019-06-11 23:59:46 -07:00
parent 2d7f4a1558
commit 02be351508
2 changed files with 17 additions and 1 deletions

View File

@ -780,6 +780,22 @@ class OneToOne(dict):
@classmethod @classmethod
def unique(cls, *a, **kw): def unique(cls, *a, **kw):
"""This alternate constructor for OneToOne will raise an exception
when input values overlap. For instance:
>>> OneToOne.unique({'a': 1, 'b': 1})
Traceback (most recent call last):
...
ValueError: expected unique values, got multiple keys for the following values: ...
This even works across inputs:
>>> a_dict = {'a': 2}
>>> OneToOne.unique(a_dict, b=2)
Traceback (most recent call last):
...
ValueError: expected unique values, got multiple keys for the following values: ...
"""
return cls(_OTO_UNIQUE_MARKER, *a, **kw) return cls(_OTO_UNIQUE_MARKER, *a, **kw)
def __setitem__(self, key, val): def __setitem__(self, key, val):

View File

@ -1,2 +1,2 @@
[pytest] [pytest]
doctest_optionflags = ALLOW_UNICODE doctest_optionflags=NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS ALLOW_UNICODE