Skip to content

pytest style #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/unit/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ def test_init_session_config_with_not_valid_key():
with pytest.raises(ConfigurationError):
_ = SessionConfig.consume(test_config_b)

assert session_config.connection_acquisition_timeout == 333
assert session_config.connection_acquisition_timeout == 333
80 changes: 80 additions & 0 deletions tests/unit/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

# Copyright (c) 2002-2020 "Neo4j,"
# Neo4j Sweden AB [http://neo4j.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import pytest

from neo4j.data import DataHydrator
from neo4j.packstream import Structure

# python -m pytest -s -v tests/unit/test_data.py


def test_can_hydrate_node_structure():
hydrant = DataHydrator()

struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
alice, = hydrant.hydrate([struct])

assert alice.id == 123
assert alice.labels == {"Person"}
assert set(alice.keys()) == {"name"}
assert alice.get("name") == "Alice"


def test_hydrating_unknown_structure_returns_same():
hydrant = DataHydrator()

struct = Structure(b'?', "foo")
mystery, = hydrant.hydrate([struct])

assert mystery == struct


def test_can_hydrate_in_list():
hydrant = DataHydrator()

struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
alice_in_list, = hydrant.hydrate([[struct]])

assert isinstance(alice_in_list, list)

alice, = alice_in_list

assert alice.id == 123
assert alice.labels == {"Person"}
assert set(alice.keys()) == {"name"}
assert alice.get("name") == "Alice"


def test_can_hydrate_in_dict():
hydrant = DataHydrator()

struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
alice_in_dict, = hydrant.hydrate([{"foo": struct}])

assert isinstance(alice_in_dict, dict)

alice = alice_in_dict["foo"]

assert alice.id == 123
assert alice.labels == {"Person"}
assert set(alice.keys()) == {"name"}
assert alice.get("name") == "Alice"
1 change: 0 additions & 1 deletion tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,3 @@ def test_neo4jerror_hydrate_with_message_and_code_client():
assert error.metadata == {}
assert error.message == "Test error message"
assert error.code == "Neo.{}.General.TestError".format(CLASSIFICATION_CLIENT)

4 changes: 2 additions & 2 deletions tests/unit/test_import_neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def test_import_graph_node():
from neo4j.graph import Node


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


Expand Down
Loading