Beispiel #1
0
 def test___ne__():
     parameter1 = query.Parameter("yep")
     parameter2 = query.Parameter("nope")
     parameter3 = unittest.mock.sentinel.parameter
     assert not parameter1 != parameter1
     assert parameter1 != parameter2
     assert parameter1 != parameter3
    def test___eq__():
        prop1 = model.Property(name="val")
        param1 = query.Parameter("abc")
        parameter_node1 = query.ParameterNode(prop1, "=", param1)
        prop2 = model.Property(name="ue")
        parameter_node2 = query.ParameterNode(prop2, "=", param1)
        parameter_node3 = query.ParameterNode(prop1, "<", param1)
        param2 = query.Parameter(900)
        parameter_node4 = query.ParameterNode(prop1, "=", param2)
        parameter_node5 = unittest.mock.sentinel.parameter_node

        assert parameter_node1 == parameter_node1
        assert not parameter_node1 == parameter_node2
        assert not parameter_node1 == parameter_node3
        assert not parameter_node1 == parameter_node4
        assert not parameter_node1 == parameter_node5
    def test___repr__():
        prop = model.Property(name="val")
        param = query.Parameter("abc")
        parameter_node = query.ParameterNode(prop, "=", param)

        expected = "ParameterNode({!r}, '=', Parameter('abc'))".format(prop)
        assert repr(parameter_node) == expected
Beispiel #4
0
    def test_resolve_missing_key():
        parameter = query.Parameter(9000)
        used = {}
        with pytest.raises(_exceptions.BadArgumentError):
            parameter.resolve({}, used)

        assert used == {}
 def test_constructor():
     prop = model.Property(name="val")
     param = query.Parameter("abc")
     parameter_node = query.ParameterNode(prop, "=", param)
     assert parameter_node._prop is prop
     assert parameter_node._op == "="
     assert parameter_node._param is param
Beispiel #6
0
    def _args_to_val(self, func, args):
        """Helper for GQL parsing to extract values from GQL expressions.

        This can extract the value from a GQL literal, return a Parameter
        for a GQL bound parameter (:1 or :foo), and interprets casts like
        KEY(...) and plain lists of values like (1, 2, 3).

        Args:
            func (str): A string indicating what kind of thing this is.
            args list[Union[int, str, Literal]]: One or more GQL values, each
                integer, string, or GQL literal.
        """
        vals = []
        for arg in args:
            if isinstance(arg, six.string_types + six.integer_types):
                val = query_module.Parameter(arg)
            else:
                val = arg.Get()
            vals.append(val)
        if func == "nop":
            return vals[0]  # May be a Parameter
        pfunc = query_module.ParameterizedFunction(func, vals)
        if pfunc.is_parameterized():
            return pfunc
        return pfunc.resolve({}, {})
Beispiel #7
0
 def test_resolve():
     key = 9000
     bound_value = "resoolt"
     parameter = query.Parameter(key)
     used = {}
     result = parameter.resolve({key: bound_value}, used)
     assert result == bound_value
     assert used == {key: True}
    def test_pickling():
        prop = model.Property(name="val")
        param = query.Parameter("abc")
        parameter_node = query.ParameterNode(prop, "=", param)

        pickled = pickle.dumps(parameter_node)
        unpickled = pickle.loads(pickled)
        assert parameter_node == unpickled
    def test_resolve():
        prop = model.Property(name="val")
        param = query.Parameter("abc")
        parameter_node = query.ParameterNode(prop, "=", param)

        used = {}
        with pytest.raises(NotImplementedError):
            parameter_node.resolve({}, used)
        assert used == {}
    def test_resolve_in_empty_container():
        prop = model.Property(name="val")
        param = query.Parameter("replace")
        parameter_node = query.ParameterNode(prop, "in", param)

        value = ()
        bindings = {"replace": value}
        used = {}
        resolved_node = parameter_node.resolve(bindings, used)

        assert resolved_node == query.FalseNode()
        assert used == {"replace": True}
    def test_resolve_simple():
        prop = model.Property(name="val")
        param = query.Parameter("abc")
        parameter_node = query.ParameterNode(prop, "=", param)

        value = 67
        bindings = {"abc": value}
        used = {}
        resolved_node = parameter_node.resolve(bindings, used)

        assert resolved_node == query.FilterNode("val", "=", value)
        assert used == {"abc": True}
    def test_resolve_with_in():
        prop = model.Property(name="val")
        param = query.Parameter("replace")
        parameter_node = query.ParameterNode(prop, "in", param)

        value = (19, 20, 28)
        bindings = {"replace": value}
        used = {}
        resolved_node = parameter_node.resolve(bindings, used)

        assert resolved_node == query.DisjunctionNode(
            query.FilterNode("val", "=", 19),
            query.FilterNode("val", "=", 20),
            query.FilterNode("val", "=", 28),
        )
        assert used == {"replace": True}
 def test__to_filter():
     prop = model.Property(name="val")
     param = query.Parameter("abc")
     parameter_node = query.ParameterNode(prop, "=", param)
     with pytest.raises(exceptions.BadArgumentError):
         parameter_node._to_filter()
Beispiel #14
0
 def test_key():
     parameter = query.Parameter(9000)
     assert parameter.key == 9000
 def test_constructor_bad_property():
     param = query.Parameter(11)
     with pytest.raises(TypeError):
         query.ParameterNode(None, "!=", param)
Beispiel #16
0
 def test___repr__():
     parameter = query.Parameter("ghi")
     assert repr(parameter) == "Parameter('ghi')"
Beispiel #17
0
 def test_constructor_invalid():
     with pytest.raises(TypeError):
         query.Parameter(None)
Beispiel #18
0
 def test_constructor():
     for key in (88, b"abc", "def"):
         parameter = query.Parameter(key)
         assert parameter._key == key
 def test_constructor_bad_op():
     prop = model.Property(name="guitar")
     param = query.Parameter("pick")
     with pytest.raises(TypeError):
         query.ParameterNode(prop, "less", param)