Skip to content

Problem with Optional in more complex definitions #49

@vltr

Description

@vltr

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions