From 02be351508d9da9910c80d13151606f1ef29c8a0 Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Tue, 11 Jun 2019 23:59:46 -0700 Subject: [PATCH] docstring/test for OneToOne.unique alternate constructor --- boltons/dictutils.py | 16 ++++++++++++++++ pytest.ini | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/boltons/dictutils.py b/boltons/dictutils.py index f700849..ce5884c 100644 --- a/boltons/dictutils.py +++ b/boltons/dictutils.py @@ -780,6 +780,22 @@ class OneToOne(dict): @classmethod 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) def __setitem__(self, key, val): diff --git a/pytest.ini b/pytest.ini index 3988cc8..4049dc7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -doctest_optionflags = ALLOW_UNICODE +doctest_optionflags=NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS ALLOW_UNICODE