renumbering chapters >= 19

This commit is contained in:
Luciano Ramalho
2021-09-10 12:34:39 -03:00
parent cbd13885fc
commit 4ae4096c4c
154 changed files with 7 additions and 1134 deletions

View File

@@ -0,0 +1,59 @@
import pytest
from checkedlib import Checked
def test_field_validation_type_error():
class Cat(Checked):
name: str
weight: float
with pytest.raises(TypeError) as e:
felix = Cat(name='Felix', weight=None)
assert str(e.value) == 'None is not compatible with weight:float'
def test_field_validation_value_error():
class Cat(Checked):
name: str
weight: float
with pytest.raises(TypeError) as e:
felix = Cat(name='Felix', weight='half stone')
assert str(e.value) == "'half stone' is not compatible with weight:float"
def test_constructor_attribute_error():
class Cat(Checked):
name: str
weight: float
with pytest.raises(AttributeError) as e:
felix = Cat(name='Felix', weight=3.2, age=7)
assert str(e.value) == "'Cat' object has no attribute 'age'"
def test_assignment_attribute_error():
class Cat(Checked):
name: str
weight: float
felix = Cat(name='Felix', weight=3.2)
with pytest.raises(AttributeError) as e:
felix.color = 'tan'
assert str(e.value) == "'Cat' object has no attribute 'color'"
def test_field_invalid_constructor():
with pytest.raises(TypeError) as e:
class Cat(Checked):
name: str
weight: None
assert str(e.value) == "'weight' type hint must be callable"