mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +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
|
from graphql.language import ast
|
||||||
|
|
||||||
|
@ -11,7 +13,9 @@ class Decimal(Scalar):
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialize(dec):
|
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))
|
'Received not compatible Decimal "{}"'.format(repr(dec))
|
||||||
)
|
)
|
||||||
return str(dec)
|
return str(dec)
|
||||||
|
@ -24,6 +28,6 @@ class Decimal(Scalar):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_value(value):
|
def parse_value(value):
|
||||||
try:
|
try:
|
||||||
return decimal.Decimal(value)
|
return _Decimal(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -21,6 +21,7 @@ def test_decimal_string_query():
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
'decimal': str(decimal_value)
|
'decimal': str(decimal_value)
|
||||||
}
|
}
|
||||||
|
assert decimal.Decimal(result.data['decimal']) == decimal_value
|
||||||
|
|
||||||
|
|
||||||
def test_decimal_string_query_variable():
|
def test_decimal_string_query_variable():
|
||||||
|
@ -34,6 +35,7 @@ def test_decimal_string_query_variable():
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
'decimal': str(decimal_value)
|
'decimal': str(decimal_value)
|
||||||
}
|
}
|
||||||
|
assert decimal.Decimal(result.data['decimal']) == decimal_value
|
||||||
|
|
||||||
|
|
||||||
def test_bad_decimal_query():
|
def test_bad_decimal_query():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user