Skip to content

Commit

Permalink
add test for no usable non-default attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dswistowski authored and Tinche committed Nov 18, 2020
1 parent 1efd738 commit 25ffce7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cattr/disambiguators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create_uniq_field_dis_func(*classes: Type) -> Callable:
if getattr(cl_fields, attr_name).default is NOTHING:
break
else:
raise Exception(f"{cl} has no usable non-default attributes.")
raise ValueError(f"{cl} has no usable non-default attributes.")
uniq_attrs_dict[attr_name] = cl
else:
fallback = cl
Expand Down
14 changes: 14 additions & 0 deletions tests/test_disambigutors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for auto-disambiguators."""
from typing import Any

import attr
import pytest

Expand Down Expand Up @@ -41,6 +43,18 @@ class D(object):
# No unique fields on either class.
create_uniq_field_dis_func(C, D)

@attr.s
class E:
pass

@attr.s
class F:
b = attr.ib(default=Any)

with pytest.raises(ValueError):
# no usable non-default attributes
create_uniq_field_dis_func(E, F)


@given(simple_classes(defaults=False))
def test_fallback(cl_and_vals):
Expand Down

0 comments on commit 25ffce7

Please sign in to comment.