forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setter.py
More file actions
59 lines (37 loc) · 1.26 KB
/
test_setter.py
File metadata and controls
59 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import unittest
from robot.utils.asserts import assert_equal, assert_raises
from robot.utils import setter, SetterAwareType
class BaseWithMeta(metaclass=SetterAwareType):
__slots__ = []
class ExampleWithSlots(BaseWithMeta):
__slots__ = []
@setter
def attr(self, value):
return value * 2
@setter
def with_doc(self, value):
"""The doc string."""
return value
class Example(ExampleWithSlots):
pass
class TestSetter(unittest.TestCase):
def setUp(self):
self.item = Example()
def test_setting(self):
self.item.attr = 1
assert_equal(self.item.attr, 2)
def test_notset(self):
assert_raises(AttributeError, getattr, self.item, 'attr')
def test_set_other_attr(self):
self.item.other_attr = 1
assert_equal(self.item.other_attr, 1)
def test_copy_doc(self):
assert_equal(type(self.item).attr.__doc__, None)
assert_equal(type(self.item).with_doc.__doc__, "The doc string.")
class TestSetterWithSlotsAndSetterAwareType(TestSetter):
def setUp(self):
self.item = ExampleWithSlots()
def test_set_other_attr(self):
assert_raises(AttributeError, setattr, self.item, 'other_attr', 1)
if __name__ == '__main__':
unittest.main()