Skip to content

Commit e1e2432

Browse files
committed
Improved options testing and coverage
1 parent 24b85d3 commit e1e2432

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

graphene/types/options.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ def __init__(self, meta=None, **defaults):
1919
for attr_name, value in defaults.items():
2020
if attr_name in meta_attrs:
2121
value = meta_attrs.pop(attr_name)
22-
elif hasattr(meta, attr_name):
23-
value = getattr(meta, attr_name)
2422
setattr(self, attr_name, value)
2523

26-
# If meta_attrs is not empty, it implicit means
24+
# If meta_attrs is not empty, it implicitly means
2725
# it received invalid attributes
2826
if meta_attrs:
2927
raise TypeError(
3028
"Invalid attributes: {}".format(
31-
','.join(meta_attrs.keys())
29+
', '.join(sorted(meta_attrs.keys()))
3230
)
3331
)
3432

3533
def __repr__(self):
36-
return '<Meta \n{} >'.format(props(self))
34+
options_props = props(self)
35+
props_as_attrs = ' '.join(['{}={}'.format(key, value) for key, value in options_props.items()])
36+
return '<Options {}>'.format(props_as_attrs)

graphene/types/tests/test_options.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
3+
from ..options import Options
4+
5+
6+
def test_options():
7+
class BaseOptions:
8+
option_1 = False
9+
name = True
10+
meta = Options(BaseOptions, name=False, option_1=False)
11+
assert meta.name == True
12+
assert meta.option_1 == False
13+
14+
15+
def test_options_extra_attrs():
16+
class BaseOptions:
17+
name = True
18+
type = True
19+
20+
with pytest.raises(Exception) as exc_info:
21+
meta = Options(BaseOptions)
22+
23+
assert str(exc_info.value) == 'Invalid attributes: name, type'
24+
25+
26+
def test_options_repr():
27+
class BaseOptions:
28+
name = True
29+
meta = Options(BaseOptions, name=False)
30+
assert repr(meta) == '<Options name=True>'

0 commit comments

Comments
 (0)