automatically generated linting fixes

This commit is contained in:
Mark Chackerian 2018-07-16 18:20:04 -04:00
parent fc3dbf0963
commit c076412ba5
2 changed files with 15 additions and 17 deletions

View File

@ -11,12 +11,13 @@ class Decimal(Scalar):
"""
The `Decimal` scalar type represents a python Decimal.
"""
@staticmethod
def serialize(dec):
if isinstance(dec, str):
dec = _Decimal(dec)
assert isinstance(dec, _Decimal), (
'Received not compatible Decimal "{}"'.format(repr(dec))
assert isinstance(dec, _Decimal), 'Received not compatible Decimal "{}"'.format(
repr(dec)
)
return str(dec)

View File

@ -11,36 +11,33 @@ class Query(ObjectType):
def resolve_decimal(self, info, input):
return input
schema = Schema(query=Query)
def test_decimal_string_query():
decimal_value = decimal.Decimal('1969.1974')
result = schema.execute('''{ decimal(input: "%s") }''' % decimal_value)
decimal_value = decimal.Decimal("1969.1974")
result = schema.execute("""{ decimal(input: "%s") }""" % decimal_value)
assert not result.errors
assert result.data == {
'decimal': str(decimal_value)
}
assert decimal.Decimal(result.data['decimal']) == decimal_value
assert result.data == {"decimal": str(decimal_value)}
assert decimal.Decimal(result.data["decimal"]) == decimal_value
def test_decimal_string_query_variable():
decimal_value = decimal.Decimal('1969.1974')
decimal_value = decimal.Decimal("1969.1974")
result = schema.execute(
'''query Test($decimal: Decimal){ decimal(input: $decimal) }''',
variable_values={'decimal': decimal_value}
"""query Test($decimal: Decimal){ decimal(input: $decimal) }""",
variable_values={"decimal": decimal_value},
)
assert not result.errors
assert result.data == {
'decimal': str(decimal_value)
}
assert decimal.Decimal(result.data['decimal']) == decimal_value
assert result.data == {"decimal": str(decimal_value)}
assert decimal.Decimal(result.data["decimal"]) == decimal_value
def test_bad_decimal_query():
not_a_decimal = "Nobody expects the Spanish Inquisition!"
result = schema.execute('''{ decimal(input: "%s") }''' % not_a_decimal)
result = schema.execute("""{ decimal(input: "%s") }""" % not_a_decimal)
assert len(result.errors) == 1
assert result.data == None