diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..1d6902327 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "neokit"] + path = neokit + url = git@github.com:nigelsmall/neokit.git diff --git a/neoget.sh b/neoget.sh deleted file mode 100755 index 12e799034..000000000 --- a/neoget.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2014-2015, Nigel Small -# -# 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. - -ACTION="download" -DIST="http://dist.neo4j.org" -ALPHA="http://alpha.neohq.net/dist" -EDITION="community" -MODE="" -CHECK_EXISTS=0 -ALL_VERSIONS="2.3.0-M02 2.2.2 2.1.8 2.0.4" -ALPHA_VERSION="3.0.0-M01-NIGHTLY" - -function usage { - SCRIPT=$(basename $0) - echo "Usage: ${SCRIPT} [] [ [ ...]]" - echo "" - echo "Download tool for Neo4j server packages." - echo "" - echo "Action Options:" - echo " -d download the latest or specific Neo4j packages (default)" - echo " -l show a list of available Neo4j versions" - echo " -h display this help text" - echo "" - echo "Other Options:" - echo " -a select the latest alpha release for download" - echo " -x only download if the file does not already exist" - echo "" - echo "Edition Options:" - echo " -c use Neo4j Community edition (default)" - echo " -e use Neo4j Enterprise edition" - echo "" - echo "List Options:" - echo " -f list only archive file names" - echo " -u list full download URLs (default)" - echo " -v list only versions" - echo "" - echo "Environment:" - echo " NEO4J_DIST - base URL for downloads (default: http://dist.neo4j.org)" - echo "" - echo "Report bugs to nigel@neotechnology.com" -} - -function list { - for VERSION in ${ALL_VERSIONS} - do - ARCHIVE="neo4j-${EDITION}-${VERSION}-unix.tar.gz" - if [ "${MODE}" == "file" ] - then - echo "${ARCHIVE}" - elif [ "${MODE}" == "version" ] - then - echo "${VERSION}" - else - echo "${DIST}/${ARCHIVE}" - fi - done -} - -function download { - for VERSION in ${VERSIONS} - do - ARCHIVE="neo4j-${EDITION}-${VERSION}-unix.tar.gz" - DOWNLOAD=1 - if [ $CHECK_EXISTS -eq 1 ] - then - if [ -f $ARCHIVE ] - then - DOWNLOAD=0 - fi - fi - if [ $DOWNLOAD -eq 1 ] - then - if [[ "$VERSIONS" == "$ALPHA_VERSION" ]] - then - URL="${ALPHA}/${ARCHIVE}" - else - URL="${DIST}/${ARCHIVE}" - fi - curl --silent --fail "${URL}" -o "${ARCHIVE}" - RESULT=$? - if [ $RESULT -eq 0 ] - then - echo "${ARCHIVE}" - else - echo 1>&2 "Cannot download archive ${URL}" - exit $RESULT - fi - else - echo "${ARCHIVE}" - fi - done -} - -while getopts ":acdefhluvx" OPTION -do - case ${OPTION} in - a) - ALL_VERSIONS="$ALPHA_VERSION" - ;; - c) - EDITION="community" - ;; - d) - ACTION="download" - ;; - e) - EDITION="enterprise" - ;; - f) - MODE="file" - ;; - h) - ACTION="help" - ;; - l) - ACTION="list" - ;; - u) - MODE="url" - ;; - v) - MODE="version" - ;; - x) - CHECK_EXISTS=1 - ;; - \?) - echo "Invalid option: -${OPTARG}" >&2 - ;; - esac -done - -shift $(($OPTIND - 1)) -if [ "$*" != "" ] -then - VERSIONS="$*" -else - set -- $ALL_VERSIONS - VERSIONS=$1 -fi - -if [ "${ACTION}" == "help" ] -then - usage -elif [ "${ACTION}" == "list" ] -then - list -else - download -fi diff --git a/neokit b/neokit new file mode 160000 index 000000000..0f5a1191e --- /dev/null +++ b/neokit @@ -0,0 +1 @@ +Subproject commit 0f5a1191e8ef642cc1180e343cb5d222c63a4eb9 diff --git a/runtests.sh b/runtests.sh index b7b8571eb..cb3e8b7ae 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,83 +1,39 @@ #!/usr/bin/env bash -if [[ $0 == /* ]] -then - HOME=$(dirname $0) -else - HOME=$(pwd)/$(dirname $0) -fi -cd ${HOME} - -DOT_TEST=${HOME}/.test -NEOGET=${HOME}/neoget.sh +# Copyright (c) 2002-2015 "Neo Technology," +# Network Engine for Objects in Lund AB [http://neotechnology.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. + +DRIVER_HOME=$(dirname $0) FORCE_DOWNLOAD=0 RUNNING=0 -function runserverandtests { - - PYTHON_VERSION=$(python --version) - NEO_VERSION=$1 - - echo "======================================================================" - echo "Running with ${PYTHON_VERSION} against Neo4j ${NEO_VERSION}" - echo "----------------------------------------------------------------------" - - cd ${HOME} - - if [ ${FORCE_DOWNLOAD} -ne 0 ] - then - rm -rf ${DOT_TEST} - fi - mkdir -p ${DOT_TEST} 2> /dev/null - - pushd ${DOT_TEST} > /dev/null - tar xf $(${NEOGET} ${NEOGET_ARGS}) - NEO_HOME=$(ls -1Ft | grep "/$" | head -1) # finds the newest directory relative to .test - echo "xx.bolt.enabled=true" >> ${NEO_HOME}/conf/neo4j-server.properties - ${NEO_HOME}/bin/neo4j start - STATUS=$? - if [ ${STATUS} -ne 0 ] - then - exit ${STATUS} - fi - popd > /dev/null - - echo -n "Testing" - coverage run -m unittest "${TESTS}" - - pushd ${DOT_TEST} > /dev/null - ${NEO_HOME}/bin/neo4j stop - rm -rf ${NEO_HOME} - popd > /dev/null - - coverage report --show-missing - - echo "======================================================================" - echo "" - -} - -function runtests { - - PYTHON_VERSION=$(python --version) - - echo "======================================================================" - echo "Running with ${PYTHON_VERSION} against running Neo4j instance" - echo "----------------------------------------------------------------------" - - cd ${HOME} - - echo -n "Testing" - coverage run -m unittest test - - coverage report --show-missing - - echo "======================================================================" - echo "" +if [ -z "${TEST}" ] +then + TEST="test" +fi -} +VERSIONS=$* +if [ "${VERSIONS}" == "" ] +then + VERSIONS="nightly" +fi +# Parse options while getopts ":dr" OPTION do case ${OPTION} in @@ -93,16 +49,26 @@ do esac done -TESTS=$1 -if [ "${TESTS}" == "" ] +# Run tests +echo "Running tests with $(python --version)" +pip install --upgrade -r ${DRIVER_HOME}/test_requirements.txt +echo "" +TEST_RUNNER="coverage run -m unittest discover -vfs ${TEST}" +if [ ${RUNNING} -eq 1 ] then - TESTS="test" + ${TEST_RUNNER} + EXIT_STATUS=$? +else + neokit/neorun "${TEST_RUNNER}" ${VERSIONS} + EXIT_STATUS=$? + if [ ${EXIT_STATUS} -eq 0 ] + then + coverage report --show-missing + fi fi -if [ ${RUNNING} -eq 1 ] +# Exit correctly +if [ ${EXIT_STATUS} -ne 0 ] then - runtests -else - NEOGET_ARGS="-eax" - runserverandtests "3.0.0-M01" + exit ${EXIT_STATUS} fi diff --git a/test/__init__.py b/test/__init__.py index 33c7a8f8b..e69de29bb 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,23 +0,0 @@ -#!/usr/bin/env python -# -*- encoding: utf-8 -*- - -# Copyright (c) 2002-2015 "Neo Technology," -# Network Engine for Objects in Lund AB [http://neotechnology.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. - -from .session_test import * -from .packstream_test import * -from .typesystem_test import * diff --git a/test/packstream_test.py b/test/test_packstream.py similarity index 99% rename from test/packstream_test.py rename to test/test_packstream.py index 74b761ff0..341d85c04 100644 --- a/test/packstream_test.py +++ b/test/test_packstream.py @@ -18,11 +18,12 @@ # See the License for the specific language governing permissions and # limitations under the License. + from collections import OrderedDict from io import BytesIO from math import pi import struct -from unittest import main, TestCase +from unittest import TestCase from neo4j.packstream import Packer, Unpacker, packb @@ -270,7 +271,3 @@ def test_empty_struct(self): def test_tiny_struct(self): assert_packable((b"Z", (u"A", 1)), b"\xB2Z\x81A\x01") - - -if __name__ == "__main__": - main() diff --git a/test/session_test.py b/test/test_session.py similarity index 92% rename from test/session_test.py rename to test/test_session.py index 6b05138fc..5dbb04f77 100644 --- a/test/session_test.py +++ b/test/test_session.py @@ -18,19 +18,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from unittest import main, TestCase + +from unittest import TestCase from neo4j import GraphDatabase, Node, Relationship, Path, CypherError class RunTestCase(TestCase): def test_must_use_valid_url_scheme(self): - try: + with self.assertRaises(ValueError): GraphDatabase.driver("x://xxx") - except ValueError: - assert True - else: - assert False def test_can_run_simple_statement(self): session = GraphDatabase.driver("bolt://localhost").session() @@ -38,25 +35,13 @@ def test_can_run_simple_statement(self): for record in session.run("RETURN 1 AS n"): assert record[0] == 1 assert record["n"] == 1 - try: - record["x"] - except AttributeError: - assert True - else: - assert False + with self.assertRaises(AttributeError): + _ = record["x"] assert record.n == 1 - try: - record.x - except AttributeError: - assert True - else: - assert False - try: - record[object()] - except TypeError: - assert True - else: - assert False + with self.assertRaises(AttributeError): + _ = record.x + with self.assertRaises(TypeError): + _ = record[object()] assert repr(record) assert len(record) == 1 count += 1 @@ -65,21 +50,13 @@ def test_can_run_simple_statement(self): def test_fails_on_bad_syntax(self): session = GraphDatabase.driver("bolt://localhost").session() - try: + with self.assertRaises(CypherError): session.run("X").consume() - except CypherError: - assert True - else: - assert False def test_fails_on_missing_parameter(self): session = GraphDatabase.driver("bolt://localhost").session() - try: + with self.assertRaises(CypherError): session.run("RETURN {x}").consume() - except CypherError: - assert True - else: - assert False def test_can_run_simple_statement_from_bytes_string(self): session = GraphDatabase.driver("bolt://localhost").session() @@ -145,12 +122,8 @@ def test_can_return_path(self): def test_can_handle_cypher_error(self): with GraphDatabase.driver("bolt://localhost").session() as session: - try: + with self.assertRaises(CypherError): session.run("X") - except CypherError: - assert True - else: - assert False def test_record_equality(self): with GraphDatabase.driver("bolt://localhost").session() as session: @@ -303,7 +276,3 @@ def test_can_rollback_transaction_using_with_block(self): result = session.run("MATCH (a) WHERE id(a) = {n} " "RETURN a.foo", {"n": node_id}) assert len(result) == 0 - - -if __name__ == "__main__": - main() diff --git a/test/typesystem_test.py b/test/test_typesystem.py similarity index 99% rename from test/typesystem_test.py rename to test/test_typesystem.py index 42c90a067..9cc6f4270 100644 --- a/test/typesystem_test.py +++ b/test/test_typesystem.py @@ -18,7 +18,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from unittest import main, TestCase + +from unittest import TestCase from neo4j.typesystem import Node, Relationship, UnboundRelationship, Path, hydrated from neo4j.packstream import Structure @@ -201,7 +202,3 @@ def test_can_hydrate_in_dict(self): assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" - - -if __name__ == "__main__": - main()