File: test_425.py

package info (click to toggle)
python-graphene 3.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,935; makefile: 214; sh: 18
file content (117 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# https://github.com/graphql-python/graphene/issues/425
# Adapted for Graphene 2.0

from graphene.types.enum import Enum, EnumOptions
from graphene.types.inputobjecttype import InputObjectType
from graphene.types.objecttype import ObjectType, ObjectTypeOptions


# ObjectType
class SpecialOptions(ObjectTypeOptions):
    other_attr = None


class SpecialObjectType(ObjectType):
    @classmethod
    def __init_subclass_with_meta__(cls, other_attr="default", **options):
        _meta = SpecialOptions(cls)
        _meta.other_attr = other_attr
        super(SpecialObjectType, cls).__init_subclass_with_meta__(
            _meta=_meta, **options
        )


def test_special_objecttype_could_be_subclassed():
    class MyType(SpecialObjectType):
        class Meta:
            other_attr = "yeah!"

    assert MyType._meta.other_attr == "yeah!"


def test_special_objecttype_could_be_subclassed_default():
    class MyType(SpecialObjectType):
        pass

    assert MyType._meta.other_attr == "default"


def test_special_objecttype_inherit_meta_options():
    class MyType(SpecialObjectType):
        pass

    assert MyType._meta.name == "MyType"
    assert MyType._meta.default_resolver is None
    assert MyType._meta.interfaces == ()


# InputObjectType
class SpecialInputObjectTypeOptions(ObjectTypeOptions):
    other_attr = None


class SpecialInputObjectType(InputObjectType):
    @classmethod
    def __init_subclass_with_meta__(cls, other_attr="default", **options):
        _meta = SpecialInputObjectTypeOptions(cls)
        _meta.other_attr = other_attr
        super(SpecialInputObjectType, cls).__init_subclass_with_meta__(
            _meta=_meta, **options
        )


def test_special_inputobjecttype_could_be_subclassed():
    class MyInputObjectType(SpecialInputObjectType):
        class Meta:
            other_attr = "yeah!"

    assert MyInputObjectType._meta.other_attr == "yeah!"


def test_special_inputobjecttype_could_be_subclassed_default():
    class MyInputObjectType(SpecialInputObjectType):
        pass

    assert MyInputObjectType._meta.other_attr == "default"


def test_special_inputobjecttype_inherit_meta_options():
    class MyInputObjectType(SpecialInputObjectType):
        pass

    assert MyInputObjectType._meta.name == "MyInputObjectType"


# Enum
class SpecialEnumOptions(EnumOptions):
    other_attr = None


class SpecialEnum(Enum):
    @classmethod
    def __init_subclass_with_meta__(cls, other_attr="default", **options):
        _meta = SpecialEnumOptions(cls)
        _meta.other_attr = other_attr
        super(SpecialEnum, cls).__init_subclass_with_meta__(_meta=_meta, **options)


def test_special_enum_could_be_subclassed():
    class MyEnum(SpecialEnum):
        class Meta:
            other_attr = "yeah!"

    assert MyEnum._meta.other_attr == "yeah!"


def test_special_enum_could_be_subclassed_default():
    class MyEnum(SpecialEnum):
        pass

    assert MyEnum._meta.other_attr == "default"


def test_special_enum_inherit_meta_options():
    class MyEnum(SpecialEnum):
        pass

    assert MyEnum._meta.name == "MyEnum"