-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathtest_attribute_copy.py
50 lines (37 loc) · 1.27 KB
/
test_attribute_copy.py
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
import dataclasses
import unittest
import marshmallow.validate
from marshmallow_dataclass import class_schema
class TestAttributesCopy(unittest.TestCase):
def test_meta_class_copied(self):
@dataclasses.dataclass
class Anything:
class Meta:
pass
schema = class_schema(Anything)
self.assertEqual(schema.Meta, Anything.Meta)
def test_validates_schema_copied(self):
@dataclasses.dataclass
class Anything:
@marshmallow.validates_schema
def validates_schema(self, *args, **kwargs):
pass
schema = class_schema(Anything)
self.assertIn("validates_schema", dir(schema))
def test_custom_method_not_copied(self):
@dataclasses.dataclass
class Anything:
def custom_method(self):
pass
schema = class_schema(Anything)
self.assertNotIn("custom_method", dir(schema))
def test_custom_property_not_copied(self):
@dataclasses.dataclass
class Anything:
@property
def custom_property(self):
return 42
schema = class_schema(Anything)
self.assertNotIn("custom_property", dir(schema))
if __name__ == "__main__":
unittest.main()