1
1
from pytest import raises
2
2
3
3
from graphene import String
4
+ from graphene .types .objecttype import ObjectTypeMeta
4
5
from ..module_loading import lazy_import , import_string
5
6
6
7
7
8
def test_import_string ():
8
9
MyString = import_string ('graphene.String' )
9
10
assert MyString == String
10
11
12
+ MyObjectTypeMeta = import_string ('graphene.ObjectType' , '__class__' )
13
+ assert MyObjectTypeMeta == ObjectTypeMeta
14
+
11
15
12
16
def test_import_string_module ():
13
17
with raises (Exception ) as exc_info :
@@ -23,7 +27,31 @@ def test_import_string_class():
23
27
assert str (exc_info .value ) == 'Module "graphene" does not define a "Stringa" attribute/class'
24
28
25
29
30
+ def test_import_string_attributes ():
31
+ with raises (Exception ) as exc_info :
32
+ import_string ('graphene.String' , 'length' )
33
+
34
+ assert str (exc_info .value ) == 'Module "graphene" does not define a "length" attribute inside attribute/class ' \
35
+ '"String"'
36
+
37
+ with raises (Exception ) as exc_info :
38
+ import_string ('graphene.ObjectType' , '__class__.length' )
39
+
40
+ assert str (exc_info .value ) == 'Module "graphene" does not define a "__class__.length" attribute inside ' \
41
+ 'attribute/class "ObjectType"'
42
+
43
+ with raises (Exception ) as exc_info :
44
+ import_string ('graphene.ObjectType' , '__classa__.__base__' )
45
+
46
+ assert str (exc_info .value ) == 'Module "graphene" does not define a "__classa__" attribute inside attribute/class ' \
47
+ '"ObjectType"'
48
+
49
+
26
50
def test_lazy_import ():
27
51
f = lazy_import ('graphene.String' )
28
52
MyString = f ()
29
53
assert MyString == String
54
+
55
+ f = lazy_import ('graphene.ObjectType' , '__class__' )
56
+ MyObjectTypeMeta = f ()
57
+ assert MyObjectTypeMeta == ObjectTypeMeta
0 commit comments