Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Optional in more complex definitions #49

Open
vltr opened this issue Jun 18, 2019 · 0 comments
Open

Problem with Optional in more complex definitions #49

vltr opened this issue Jun 18, 2019 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@vltr
Copy link
Owner

vltr commented Jun 18, 2019

middle/tests/test_types.py

Lines 953 to 969 in d3fc3f9

@pytest.mark.xfail # ! TODO - this shoud not fail on pytest.raises
def test_tuple_no_optional():
opt_tup = t.Tuple[float, int]
class TestModel(middle.Model):
value = middle.field(
type=t.Dict[int, t.Tuple[opt_tup, opt_tup, opt_tup, opt_tup]]
)
inst = TestModel(value={1: [[0.9, 1], [0.9, 1], [2.1, 2], [2.1, 2]]})
assert inst.value[1][0] == (0.9, 1)
assert inst.value[1][1] == (0.9, 1)
assert inst.value[1][2] == (2.1, 2)
assert inst.value[1][3] == (2.1, 2)
with pytest.raises(ValidationError):
TestModel(value={5: [[0.9, 1], None, [2.1, 2], None]})

The definition above should produce a ValidationError, since it's not Optional, hence the values on given for Tuples must not be null or None.

@vltr vltr added the bug Something isn't working label Jun 18, 2019
@vltr vltr self-assigned this Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant