|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +# Copyright (c) 2002-2020 "Neo4j," |
| 5 | +# Neo4j Sweden AB [http://neo4j.com] |
| 6 | +# |
| 7 | +# This file is part of Neo4j. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | + |
| 21 | + |
| 22 | +def test_data_with_one_key_and_no_records(session): |
| 23 | + result = session.run("UNWIND range(1, 0) AS n RETURN n") |
| 24 | + assert result.data() == [] |
| 25 | + |
| 26 | + |
| 27 | +def test_multiple_data(session): |
| 28 | + result = session.run("UNWIND range(1, 3) AS n " |
| 29 | + "RETURN 1 * n AS x, 2 * n AS y, 3 * n AS z") |
| 30 | + assert result.data() == [{"x": 1, "y": 2, "z": 3}, |
| 31 | + {"x": 2, "y": 4, "z": 6}, |
| 32 | + {"x": 3, "y": 6, "z": 9}] |
| 33 | + |
| 34 | + |
| 35 | +def test_multiple_indexed_data(session): |
| 36 | + result = session.run("UNWIND range(1, 3) AS n " |
| 37 | + "RETURN 1 * n AS x, 2 * n AS y, 3 * n AS z") |
| 38 | + assert result.data(2, 0) == [{"x": 1, "z": 3}, |
| 39 | + {"x": 2, "z": 6}, |
| 40 | + {"x": 3, "z": 9}] |
| 41 | + |
| 42 | + |
| 43 | +def test_multiple_keyed_data(session): |
| 44 | + result = session.run("UNWIND range(1, 3) AS n " |
| 45 | + "RETURN 1 * n AS x, 2 * n AS y, 3 * n AS z") |
| 46 | + assert result.data("z", "x") == [{"x": 1, "z": 3}, |
| 47 | + {"x": 2, "z": 6}, |
| 48 | + {"x": 3, "z": 9}] |
| 49 | + |
| 50 | + |
| 51 | +def test_single_data(session): |
| 52 | + result = session.run("RETURN 1 AS x, 2 AS y, 3 AS z") |
| 53 | + assert result.single().data() == {"x": 1, "y": 2, "z": 3} |
| 54 | + |
| 55 | + |
| 56 | +def test_single_indexed_data(session): |
| 57 | + result = session.run("RETURN 1 AS x, 2 AS y, 3 AS z") |
| 58 | + assert result.single().data(2, 0) == {"x": 1, "z": 3} |
| 59 | + |
| 60 | + |
| 61 | +def test_single_keyed_data(session): |
| 62 | + result = session.run("RETURN 1 AS x, 2 AS y, 3 AS z") |
| 63 | + assert result.single().data("z", "x") == {"x": 1, "z": 3} |
| 64 | + |
| 65 | + |
| 66 | +def test_none(session): |
| 67 | + result = session.run("RETURN null AS x") |
| 68 | + assert result.data() == [{"x": None}] |
| 69 | + |
| 70 | + |
| 71 | +def test_bool(session): |
| 72 | + result = session.run("RETURN true AS x, false AS y") |
| 73 | + assert result.data() == [{"x": True, "y": False}] |
| 74 | + |
| 75 | + |
| 76 | +def test_int(session): |
| 77 | + result = session.run("RETURN 1 AS x, 2 AS y, 3 AS z") |
| 78 | + assert result.data() == [{"x": 1, "y": 2, "z": 3}] |
| 79 | + |
| 80 | + |
| 81 | +def test_float(session): |
| 82 | + result = session.run("RETURN 0.0 AS x, 1.0 AS y, 3.141592653589 AS z") |
| 83 | + assert result.data() == [{"x": 0.0, "y": 1.0, "z": 3.141592653589}] |
| 84 | + |
| 85 | + |
| 86 | +def test_string(session): |
| 87 | + result = session.run("RETURN 'hello, world' AS x") |
| 88 | + assert result.data() == [{"x": "hello, world"}] |
| 89 | + |
| 90 | + |
| 91 | +def test_byte_array(session): |
| 92 | + result = session.run("RETURN $x AS x", x=bytearray([1, 2, 3])) |
| 93 | + assert result.data() == [{"x": bytearray([1, 2, 3])}] |
| 94 | + |
| 95 | + |
| 96 | +def test_list(session): |
| 97 | + result = session.run("RETURN [1, 2, 3] AS x") |
| 98 | + assert result.data() == [{"x": [1, 2, 3]}] |
| 99 | + |
| 100 | + |
| 101 | +def test_dict(session): |
| 102 | + result = session.run("RETURN {one: 1, two: 2} AS x") |
| 103 | + assert result.data() == [{"x": {"one": 1, "two": 2}}] |
| 104 | + |
| 105 | + |
| 106 | +def test_node(session): |
| 107 | + result = session.run("CREATE (x:Person {name:'Alice'}) RETURN x") |
| 108 | + assert result.data() == [{"x": {"name": "Alice"}}] |
| 109 | + |
| 110 | + |
| 111 | +def test_relationship_with_pre_known_nodes(session): |
| 112 | + result = session.run("CREATE (a:Person {name:'Alice'})-[x:KNOWS {since:1999}]->(b:Person {name:'Bob'}) " |
| 113 | + "RETURN a, b, x") |
| 114 | + assert result.data() == [{"a": {"name": "Alice"}, "b": {"name": "Bob"}, |
| 115 | + "x": ({"name": "Alice"}, "KNOWS", {"name": "Bob"})}] |
| 116 | + |
| 117 | + |
| 118 | +def test_relationship_with_post_known_nodes(session): |
| 119 | + result = session.run("CREATE (a:Person {name:'Alice'})-[x:KNOWS {since:1999}]->(b:Person {name:'Bob'}) " |
| 120 | + "RETURN x, a, b") |
| 121 | + assert result.data() == [{"x": ({"name": "Alice"}, "KNOWS", {"name": "Bob"}), |
| 122 | + "a": {"name": "Alice"}, "b": {"name": "Bob"}}] |
| 123 | + |
| 124 | + |
| 125 | +def test_relationship_with_unknown_nodes(session): |
| 126 | + result = session.run("CREATE (:Person {name:'Alice'})-[x:KNOWS {since:1999}]->(:Person {name:'Bob'}) " |
| 127 | + "RETURN x") |
| 128 | + assert result.data() == [{"x": ({}, "KNOWS", {})}] |
| 129 | + |
| 130 | + |
| 131 | +def test_path(session): |
| 132 | + result = session.run("CREATE x = (a:Person {name:'Alice'})-[:KNOWS {since:1999}]->(b:Person {name:'Bob'}) " |
| 133 | + "RETURN x") |
| 134 | + assert result.data() == [{"x": [{"name": "Alice"}, "KNOWS", {"name": "Bob"}]}] |
0 commit comments