def _run_test_case(self, value, type_, expected, error, variables=None):
     if error is None:
         assert (value_from_ast(parse_value(value), type_,
                                variables) == expected)
     else:
         with pytest.raises(error):
             value_from_ast(parse_value(value), type_, variables)
Exemple #2
0
def test_parse_value_it_parses_block_strings():
    assert_node_equal(
        parse_value('["""long""" "short"]'),
        _ast.ListValue(
            loc=(0, 20),
            values=[
                _ast.StringValue(loc=(1, 11), value="long", block=True),
                _ast.StringValue(loc=(12, 19), value="short"),
            ],
        ),
    )
Exemple #3
0
def test_parse_value_it_parses_list_values():
    assert_node_equal(
        parse_value('[123 "abc"]'),
        _ast.ListValue(
            loc=(0, 11),
            values=[
                _ast.IntValue(loc=(1, 4), value="123"),
                _ast.StringValue(loc=(5, 10), value="abc"),
            ],
        ),
    )
    def test_it_raises_on_null_variable_with_non_null_type(self):
        with pytest.raises(InvalidValue) as exc_info:
            value_from_ast(
                parse_value("$testVariable"),
                NonNullBool,
                {"testVariable": None},
            )

        assert str(exc_info.value) == (
            'Variable "$testVariable" used for type "Boolean!" '
            "must not be null.")
Exemple #5
0
 def test_parse_literal_non_string(self):
     p = re.compile(r"^[a-d]+$", re.IGNORECASE)
     t = RegexType("RE", p)
     with pytest.raises(ScalarParsingError) as exc_info:
         t.parse_literal(parse_value("1"))  # type: ignore
     assert str(exc_info.value) == "Invalid literal IntValue"
Exemple #6
0
 def test_parse_literal_fail(self):
     p = re.compile(r"^[a-d]+$", re.IGNORECASE)
     t = RegexType("RE", p)
     with pytest.raises(ScalarParsingError) as exc_info:
         t.parse_literal(parse_value('"aF"'))  # type: ignore
     assert str(exc_info.value) == '"aF" does not match pattern "^[a-d]+$"'
Exemple #7
0
 def test_parse_literal_ok(self):
     p = re.compile(r"^[a-d]+$", re.IGNORECASE)
     t = RegexType("RE", p)
     assert t.parse_literal(parse_value('"aBcD"')) == "aBcD"  # type: ignore
Exemple #8
0
def test_parse_value_it_parses_null_value():
    assert_node_equal(parse_value("null"), _ast.NullValue(loc=(0, 4)))
 def test_it_raises_on_unknown_variables(self):
     with pytest.raises(UnknownVariable) as exc_info:
         untyped_value_from_ast(parse_value("$testVariable"), {})
     assert str(exc_info.value) == "testVariable"
Exemple #10
0
 def test_it_parses_variables(self, value, variables, expected):
     assert untyped_value_from_ast(parse_value(value),
                                   variables) == expected
Exemple #11
0
 def test_it_parses_enum_values_as_plain_strings(self, value, expected):
     assert untyped_value_from_ast(parse_value(value)) == expected
Exemple #12
0
 def test_it_parses_input_objects(self, value, expected):
     assert untyped_value_from_ast(parse_value(value)) == expected
Exemple #13
0
 def test_it_parses_list_values(self, value, expected):
     assert untyped_value_from_ast(parse_value(value)) == expected
Exemple #14
0
 def test_it_raises_on_non_nullable_null(self):
     with pytest.raises(InvalidValue):
         value_from_ast(parse_value("null"), NonNullType(Boolean), None)
Exemple #15
0
 def test_it_coerces_nullable_to_none(self):
     assert value_from_ast(parse_value("null"), Boolean, None) is None