4
4
from graphql .type import (
5
5
GraphQLArgument ,
6
6
GraphQLDeprecatedDirective ,
7
+ GraphQLBoolean ,
7
8
GraphQLDirective ,
8
9
GraphQLEnumType ,
10
+ GraphQLField ,
11
+ GraphQLFloat ,
12
+ GraphQLID ,
9
13
GraphQLIncludeDirective ,
10
14
GraphQLInputField ,
11
15
GraphQLInputObjectType ,
16
+ GraphQLInt ,
12
17
GraphQLInterfaceType ,
13
18
GraphQLList ,
14
19
GraphQLNonNull ,
19
24
GraphQLUnionType ,
20
25
assert_abstract_type ,
21
26
assert_composite_type ,
27
+ assert_directive ,
22
28
assert_enum_type ,
23
29
assert_input_object_type ,
24
30
assert_input_type ,
54
60
is_output_type ,
55
61
is_scalar_type ,
56
62
is_specified_directive ,
63
+ is_specified_scalar_type ,
57
64
is_type ,
58
65
is_union_type ,
59
66
is_wrapping_type ,
64
71
UnionType = GraphQLUnionType ("Union" , types = [ObjectType ])
65
72
EnumType = GraphQLEnumType ("Enum" , values = {"foo" : {}})
66
73
InputObjectType = GraphQLInputObjectType ("InputObject" , {})
67
- ScalarType = GraphQLScalarType (
68
- "Scalar" , serialize = lambda : {}, parse_value = lambda : {}, parse_literal = lambda : {}
69
- )
74
+ ScalarType = GraphQLScalarType ("Scalar" , lambda : None )
75
+ Directive = GraphQLDirective ("Directive" , [DirectiveLocation .QUERY ])
70
76
71
77
72
78
def describe_type_predicates ():
@@ -100,10 +106,65 @@ def returns_true_for_custom_scalar():
100
106
assert is_scalar_type (ScalarType ) is True
101
107
assert_scalar_type (ScalarType )
102
108
109
+ def returns_fals_for_scalar_class_rather_than_instance ():
110
+ assert is_scalar_type (GraphQLScalarType ) is False
111
+ with raises (TypeError ):
112
+ assert_scalar_type (GraphQLScalarType )
113
+
114
+ def returns_false_for_wrapped_scalar ():
115
+ assert is_scalar_type (GraphQLList (ScalarType )) is False
116
+ with raises (TypeError ):
117
+ assert_scalar_type (GraphQLList (ScalarType ))
118
+
103
119
def returns_false_for_non_scalar ():
104
120
assert is_scalar_type (EnumType ) is False
105
121
with raises (TypeError ):
106
122
assert_scalar_type (EnumType )
123
+ assert is_scalar_type (Directive ) is False
124
+ with raises (TypeError ):
125
+ assert_scalar_type (Directive )
126
+
127
+ def returns_false_for_random_garbage ():
128
+ assert is_scalar_type (None ) is False
129
+ with raises (TypeError ):
130
+ assert_scalar_type (None )
131
+ assert is_scalar_type ({"what" : "is this" }) is False
132
+ with raises (TypeError ):
133
+ assert_scalar_type ({"what" : "is this" })
134
+
135
+ def describe_is_specified_scalar_type ():
136
+ def returns_true_for_specified_scalars ():
137
+ assert is_specified_scalar_type (GraphQLString ) is True
138
+ assert is_specified_scalar_type (GraphQLInt ) is True
139
+ assert is_specified_scalar_type (GraphQLFloat ) is True
140
+ assert is_specified_scalar_type (GraphQLBoolean ) is True
141
+ assert is_specified_scalar_type (GraphQLID ) is True
142
+
143
+ def returns_false_for_custom_scalar ():
144
+ assert is_specified_scalar_type (ScalarType ) is False
145
+
146
+ def returns_fals_for_scalar_class_rather_than_specified_instance ():
147
+ assert is_specified_scalar_type (GraphQLScalarType ) is False
148
+
149
+ def returns_false_for_wrapped_specified_scalar ():
150
+ assert is_scalar_type (GraphQLList (GraphQLString )) is False
151
+
152
+ def returns_false_for_non_scalar ():
153
+ assert is_specified_scalar_type (EnumType ) is False
154
+ assert is_specified_scalar_type (Directive ) is False
155
+
156
+ def returns_false_for_spec_defined_directive ():
157
+ assert is_specified_scalar_type (GraphQLSkipDirective ) is False
158
+
159
+ def returns_false_for_object_type_named_like_specified_directive ():
160
+ ObjectNamedLikeScalar = GraphQLObjectType (
161
+ "String" , {"serialize" : GraphQLField (GraphQLString )}
162
+ )
163
+ assert is_specified_scalar_type (ObjectNamedLikeScalar ) is False
164
+
165
+ def returns_false_for_random_garbage ():
166
+ assert is_specified_scalar_type (None ) is False
167
+ assert is_specified_scalar_type ({"what" : "is this" }) is False
107
168
108
169
def describe_is_object_type ():
109
170
def returns_true_for_object_type ():
@@ -463,23 +524,34 @@ def returns_false_for_optional_input_field():
463
524
464
525
def describe_directive_predicates ():
465
526
def describe_is_directive ():
466
- def returns_true_for_directives ():
467
- directive = GraphQLDirective ("Foo" , [DirectiveLocation .QUERY ])
468
- assert is_directive (directive ) is True
527
+ def returns_true_for_spec_defined_directive ():
469
528
assert is_directive (GraphQLSkipDirective ) is True
529
+ assert_directive (GraphQLSkipDirective )
530
+
531
+ def returns_true_for_custom_directive ():
532
+ assert is_directive (Directive ) is True
533
+ assert_directive (Directive )
470
534
471
535
def returns_false_for_directive_class_rather_than_instance ():
472
536
assert is_directive (GraphQLDirective ) is False
537
+ with raises (TypeError ):
538
+ assert_directive (GraphQLScalarType )
473
539
474
- def returns_false_for_object_type ():
475
- assert is_directive (ObjectType ) is False
476
-
477
- def returns_false_for_scalar_type ():
478
- assert is_directive (GraphQLString ) is False
540
+ def returns_false_for_non_directive ():
541
+ assert is_directive (EnumType ) is False
542
+ with raises (TypeError ):
543
+ assert_directive (EnumType )
544
+ assert is_directive (ScalarType ) is False
545
+ with raises (TypeError ):
546
+ assert_directive (ScalarType )
479
547
480
548
def returns_false_for_random_garbage ():
481
549
assert is_directive (None ) is False
550
+ with raises (TypeError ):
551
+ assert_directive (None )
482
552
assert is_directive ({"what" : "is this" }) is False
553
+ with raises (TypeError ):
554
+ assert_directive ({"what" : "is this" })
483
555
484
556
def describe_is_specified_directive ():
485
557
def returns_true_for_specified_directives ():
@@ -488,25 +560,21 @@ def returns_true_for_specified_directives():
488
560
assert is_specified_directive (GraphQLDeprecatedDirective ) is True
489
561
490
562
def returns_false_for_custom_directive ():
491
- directive = GraphQLDirective ("Foo" , [DirectiveLocation .QUERY ])
492
- assert is_specified_directive (directive ) is False
563
+ assert is_specified_directive (Directive ) is False
493
564
494
- def returns_false_for_directive_class_rather_than_instance ():
565
+ def returns_false_for_directive_class_rather_than_specified_instance ():
495
566
assert is_specified_directive (GraphQLDirective ) is False
496
567
497
- def returns_false_for_object_type ():
498
- assert is_specified_directive (ObjectType ) is False
568
+ def returns_false_for_non_directive ():
569
+ assert is_specified_directive (EnumType ) is False
570
+ assert is_specified_directive (ScalarType ) is False
499
571
500
572
def returns_false_for_spec_defined_scalar_type ():
501
573
assert is_specified_directive (GraphQLString ) is False
502
574
503
- def returns_false_for_scalar_type_with_name_of_specified_directive ():
504
- assert (
505
- is_specified_directive (
506
- GraphQLScalarType ("deprecated" , lambda : None )
507
- )
508
- is False
509
- )
575
+ def returns_false_for_scalar_type_named_like_specified_directive ():
576
+ ScalarNamedLikeDirective = GraphQLScalarType ("deprecated" , lambda : None )
577
+ assert is_specified_directive (ScalarNamedLikeDirective ) is False
510
578
511
579
def returns_false_for_random_garbage ():
512
580
assert is_specified_directive (None ) is False
0 commit comments