Skip to content

Commit dea240e

Browse files
pytest style (#376)
refactored the unit tests to be pytest style
1 parent 2c702a6 commit dea240e

File tree

7 files changed

+429
-350
lines changed

7 files changed

+429
-350
lines changed

tests/unit/test_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ def test_init_session_config_with_not_valid_key():
222222
with pytest.raises(ConfigurationError):
223223
_ = SessionConfig.consume(test_config_b)
224224

225-
assert session_config.connection_acquisition_timeout == 333
225+
assert session_config.connection_acquisition_timeout == 333

tests/unit/test_data.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
import pytest
23+
24+
from neo4j.data import DataHydrator
25+
from neo4j.packstream import Structure
26+
27+
# python -m pytest -s -v tests/unit/test_data.py
28+
29+
30+
def test_can_hydrate_node_structure():
31+
hydrant = DataHydrator()
32+
33+
struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
34+
alice, = hydrant.hydrate([struct])
35+
36+
assert alice.id == 123
37+
assert alice.labels == {"Person"}
38+
assert set(alice.keys()) == {"name"}
39+
assert alice.get("name") == "Alice"
40+
41+
42+
def test_hydrating_unknown_structure_returns_same():
43+
hydrant = DataHydrator()
44+
45+
struct = Structure(b'?', "foo")
46+
mystery, = hydrant.hydrate([struct])
47+
48+
assert mystery == struct
49+
50+
51+
def test_can_hydrate_in_list():
52+
hydrant = DataHydrator()
53+
54+
struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
55+
alice_in_list, = hydrant.hydrate([[struct]])
56+
57+
assert isinstance(alice_in_list, list)
58+
59+
alice, = alice_in_list
60+
61+
assert alice.id == 123
62+
assert alice.labels == {"Person"}
63+
assert set(alice.keys()) == {"name"}
64+
assert alice.get("name") == "Alice"
65+
66+
67+
def test_can_hydrate_in_dict():
68+
hydrant = DataHydrator()
69+
70+
struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
71+
alice_in_dict, = hydrant.hydrate([{"foo": struct}])
72+
73+
assert isinstance(alice_in_dict, dict)
74+
75+
alice = alice_in_dict["foo"]
76+
77+
assert alice.id == 123
78+
assert alice.labels == {"Person"}
79+
assert set(alice.keys()) == {"name"}
80+
assert alice.get("name") == "Alice"

tests/unit/test_exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,3 @@ def test_neo4jerror_hydrate_with_message_and_code_client():
217217
assert error.metadata == {}
218218
assert error.message == "Test error message"
219219
assert error.code == "Neo.{}.General.TestError".format(CLASSIFICATION_CLIENT)
220-

tests/unit/test_import_neo4j.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def test_import_graph_node():
144144
from neo4j.graph import Node
145145

146146

147-
def test_import_graph_Path():
148-
# python -m pytest tests/unit/test_import_neo4j.py -s -v -k test_import_graph_Path
147+
def test_import_graph_path():
148+
# python -m pytest tests/unit/test_import_neo4j.py -s -v -k test_import_graph_path
149149
from neo4j.graph import Path
150150

151151

0 commit comments

Comments
 (0)