Merge branch 'master' into node-parent-type

This commit is contained in:
markus 2016-11-10 10:55:15 +00:00
commit c01a9b1843
4 changed files with 69 additions and 6 deletions

View File

@ -71,18 +71,18 @@ def _is_descriptor(obj):
def _is_dunder(name): def _is_dunder(name):
"""Returns True if a __dunder__ name, False otherwise.""" """Returns True if a __dunder__ name, False otherwise."""
return (name[:2] == name[-2:] == '__' and return (len(name) > 4 and
name[:2] == name[-2:] == '__' and
name[2:3] != '_' and name[2:3] != '_' and
name[-3:-2] != '_' and name[-3:-2] != '_')
len(name) > 4)
def _is_sunder(name): def _is_sunder(name):
"""Returns True if a _sunder_ name, False otherwise.""" """Returns True if a _sunder_ name, False otherwise."""
return (name[0] == name[-1] == '_' and return (len(name) > 2 and
name[0] == name[-1] == '_' and
name[1:2] != '_' and name[1:2] != '_' and
name[-2:-1] != '_' and name[-2:-1] != '_')
len(name) > 2)
def _make_class_unpicklable(cls): def _make_class_unpicklable(cls):

View File

View File

@ -0,0 +1,41 @@
from ..enum import _is_dunder, _is_sunder
def test__is_dunder():
dunder_names = [
'__i__',
'__test__',
]
non_dunder_names = [
'test',
'__test',
'_test',
'_test_',
'test__',
'',
]
for name in dunder_names:
assert _is_dunder(name) is True
for name in non_dunder_names:
assert _is_dunder(name) is False
def test__is_sunder():
sunder_names = [
'_i_',
'_test_',
]
non_sunder_names = [
'__i__',
'_i__',
'__i_',
'',
]
for name in sunder_names:
assert _is_sunder(name) is True
for name in non_sunder_names:
assert _is_sunder(name) is False

View File

@ -0,0 +1,22 @@
from ..node import Node, GlobalID
from ...types import NonNull, ID
class CustomNode(Node):
class Meta:
name = 'Node'
def test_global_id_defaults_to_required_and_node():
gid = GlobalID()
assert isinstance(gid.type, NonNull)
assert gid.type.of_type == ID
assert gid.node == Node
def test_global_id_allows_overriding_of_node_and_required():
gid = GlobalID(node=CustomNode, required=False)
assert gid.type == ID
assert gid.node == CustomNode