1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
from functools import partial
import pytest
from ..argument import Argument, to_arguments
from ..field import Field
from ..inputfield import InputField
from ..scalars import String
from ..structures import NonNull
def test_argument():
arg = Argument(String, default_value="a", description="desc", name="b")
assert arg.type == String
assert arg.default_value == "a"
assert arg.description == "desc"
assert arg.name == "b"
def test_argument_comparasion():
arg1 = Argument(String, name="Hey", description="Desc", default_value="default")
arg2 = Argument(String, name="Hey", description="Desc", default_value="default")
assert arg1 == arg2
assert arg1 != String()
def test_argument_required():
arg = Argument(String, required=True)
assert arg.type == NonNull(String)
def test_to_arguments():
args = {"arg_string": Argument(String), "unmounted_arg": String(required=True)}
my_args = to_arguments(args)
assert my_args == {
"arg_string": Argument(String),
"unmounted_arg": Argument(String, required=True),
}
def test_to_arguments_raises_if_field():
args = {"arg_string": Field(String)}
with pytest.raises(ValueError) as exc_info:
to_arguments(args)
assert str(exc_info.value) == (
"Expected arg_string to be Argument, but received Field. Try using "
"Argument(String)."
)
def test_to_arguments_raises_if_inputfield():
args = {"arg_string": InputField(String)}
with pytest.raises(ValueError) as exc_info:
to_arguments(args)
assert str(exc_info.value) == (
"Expected arg_string to be Argument, but received InputField. Try "
"using Argument(String)."
)
def test_argument_with_lazy_type():
MyType = object()
arg = Argument(lambda: MyType)
assert arg.type == MyType
def test_argument_with_lazy_partial_type():
MyType = object()
arg = Argument(partial(lambda: MyType))
assert arg.type == MyType
|