Skip to content

Commit a427a0f

Browse files
author
Timothy Laurent
committed
Add test for _is_sunder and _is_dunder array.py functions.
1 parent 50eadde commit a427a0f

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

graphene/pyutils/enum.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ def _is_descriptor(obj):
7171

7272
def _is_dunder(name):
7373
"""Returns True if a __dunder__ name, False otherwise."""
74-
return (name[:2] == name[-2:] == '__' and
74+
return (len(name) > 4 and
75+
name[:2] == name[-2:] == '__' and
7576
name[2:3] != '_' and
76-
name[-3:-2] != '_' and
77-
len(name) > 4)
77+
name[-3:-2] != '_')
7878

7979

8080
def _is_sunder(name):
8181
"""Returns True if a _sunder_ name, False otherwise."""
82-
return (name[0] == name[-1] == '_' and
82+
return (len(name) > 2 and
83+
name[0] == name[-1] == '_' and
8384
name[1:2] != '_' and
84-
name[-2:-1] != '_' and
85-
len(name) > 2)
85+
name[-2:-1] != '_')
8686

8787

8888
def _make_class_unpicklable(cls):

graphene/pyutils/tests/__init__.py

Whitespace-only changes.

graphene/pyutils/tests/test_enum.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from ..enum import _is_dunder, _is_sunder
2+
3+
4+
def test__is_dunder():
5+
dunder_names = [
6+
'__i__',
7+
'__test__',
8+
]
9+
non_dunder_names = [
10+
'test',
11+
'__test',
12+
'_test',
13+
'_test_',
14+
'test__',
15+
'',
16+
]
17+
18+
for name in dunder_names:
19+
assert _is_dunder(name) is True
20+
21+
for name in non_dunder_names:
22+
assert _is_dunder(name) is False
23+
24+
def test__is_sunder():
25+
sunder_names = [
26+
'_i_',
27+
'_test_',
28+
]
29+
30+
non_sunder_names = [
31+
'__i__',
32+
'_i__',
33+
'__i_',
34+
'',
35+
]
36+
37+
for name in sunder_names:
38+
assert _is_sunder(name) is True
39+
40+
for name in non_sunder_names:
41+
assert _is_sunder(name) is False

0 commit comments

Comments
 (0)