Added __str__ to object type.

This commit is contained in:
Markus Padourek 2016-09-19 13:14:32 +01:00
parent 8e320da051
commit 9a69cf9413
3 changed files with 23 additions and 0 deletions

1
.gitignore vendored
View File

@ -75,6 +75,7 @@ target/
# PyCharm
.idea
*.iml
# Databases
*.sqlite3

View File

@ -3,6 +3,7 @@ from collections import OrderedDict
import six
from ..utils.is_base_type import is_base_type
from ..pyutils.type_to_string import object_type_to_string
from .abstracttype import AbstractTypeMeta
from .interface import Interface
from .options import Options
@ -106,3 +107,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta)):
self.__class__.__name__
)
)
def __repr__(self):
return object_type_to_string(self, full_package_name=True)
def __str__(self):
return object_type_to_string(self)

View File

@ -1,3 +1,4 @@
from mock import patch, call
import pytest
from ..abstracttype import AbstractType
@ -173,3 +174,17 @@ def test_objecttype_container_benchmark(benchmark):
@benchmark
def create_objecttype():
Container(field1='field1', field2='field2')
@patch('graphene.types.objecttype.object_type_to_string', return_value='')
def test_repr_calls_right_implementation(mock_impl):
c1 = Container()
repr(c1)
assert mock_impl.call_count == 1
@patch('graphene.types.objecttype.object_type_to_string', return_value='')
def test_str_calls_right_implementation(mock_impl):
c1 = Container()
str(c1)
assert mock_impl.call_count == 1