mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
should fix some import issues with python 2.7
This commit is contained in:
parent
de050fa6db
commit
0fdc2ca3eb
|
@ -1,4 +1,6 @@
|
|||
import decimal
|
||||
from __future__ import absolute_import
|
||||
|
||||
from decimal import Decimal as _Decimal
|
||||
|
||||
from graphql.language import ast
|
||||
|
||||
|
@ -11,7 +13,9 @@ class Decimal(Scalar):
|
|||
"""
|
||||
@staticmethod
|
||||
def serialize(dec):
|
||||
assert isinstance(dec, decimal.Decimal), (
|
||||
if isinstance(dec, str):
|
||||
dec = _Decimal(dec)
|
||||
assert isinstance(dec, _Decimal), (
|
||||
'Received not compatible Decimal "{}"'.format(repr(dec))
|
||||
)
|
||||
return str(dec)
|
||||
|
@ -24,6 +28,6 @@ class Decimal(Scalar):
|
|||
@staticmethod
|
||||
def parse_value(value):
|
||||
try:
|
||||
return decimal.Decimal(value)
|
||||
return _Decimal(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
|
|
@ -21,6 +21,7 @@ def test_decimal_string_query():
|
|||
assert result.data == {
|
||||
'decimal': str(decimal_value)
|
||||
}
|
||||
assert decimal.Decimal(result.data['decimal']) == decimal_value
|
||||
|
||||
|
||||
def test_decimal_string_query_variable():
|
||||
|
@ -34,6 +35,7 @@ def test_decimal_string_query_variable():
|
|||
assert result.data == {
|
||||
'decimal': str(decimal_value)
|
||||
}
|
||||
assert decimal.Decimal(result.data['decimal']) == decimal_value
|
||||
|
||||
|
||||
def test_bad_decimal_query():
|
||||
|
|
Loading…
Reference in New Issue
Block a user