File: test_attribute_copy.py

package info (click to toggle)
python-marshmallow-dataclass 8.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: python: 2,351; makefile: 11; sh: 6
file content (50 lines) | stat: -rw-r--r-- 1,299 bytes parent folder | download | duplicates (3)
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()