From 66a8f0f9541d902a55f5180b17134e07bf09858f Mon Sep 17 00:00:00 2001 From: Zhen Date: Mon, 9 May 2016 14:28:20 +0200 Subject: [PATCH 1/4] Chaning to use new neokit to start and stop server --- .gitmodules | 4 +- neokit | 2 +- requirements.txt | 0 runtests.py | 118 +++++++++++++++++++++++++++++++++++++++++++++++ runtests.sh | 115 --------------------------------------------- 5 files changed, 121 insertions(+), 118 deletions(-) delete mode 100644 requirements.txt create mode 100644 runtests.py delete mode 100755 runtests.sh diff --git a/.gitmodules b/.gitmodules index 83904f5af..940f8c3d4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "neokit"] - path = neokit - url = https://github.com/nigelsmall/neokit.git + path = neokit + url = https://github.com/neo-technology/neokit.git diff --git a/neokit b/neokit index c206a8317..60cac056f 160000 --- a/neokit +++ b/neokit @@ -1 +1 @@ -Subproject commit c206a831783d9ea352cca8c1b2772927cbcae91e +Subproject commit 60cac056f07bc63d02121e3908315962e0746caf diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/runtests.py b/runtests.py new file mode 100644 index 000000000..dfc301d22 --- /dev/null +++ b/runtests.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +# Copyright (c) 2002-2016 "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. + +""" +Usage: runtests.py + --test=name : run this specific test + --test : run all unit tests + --examples : run all example tests + --tck : run tck tests + -h : show this help message +example: + python ./runtests.py --test --examples --tck +""" +from sys import argv, stdout, exit +from os import name, path +from atexit import register +import subprocess +import getopt + +UNITTEST_RUNNER = "coverage run -m unittest discover -vfs " +BEHAVE_RUNNER="behave --tags=-db --tags=-tls --tags=-fixed_session_pool test/tck" + +NEORUN_PATH = path.abspath('./neokit/neorun.py') +NEO4J_HOME = path.abspath('./resources/neo4jhome') + +is_windows = (name == 'nt') + + +def runcommand(command): + commands = command.split() + return runcommands(commands) + + +def runcommands(commands): + if is_windows: + commands = ['powershell.exe'] + commands + return run0(commands) + + +def run0(commands): + stdout.write("Running commands: %s\n" % commands) + p = subprocess.Popen(commands, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + retcode = p.wait() + stdout.write(out) + stdout.write(err) + return retcode + + +def neorun(command): + runcommand('python ' + NEORUN_PATH + ' ' + command) + + +def main(): + if len(argv) <= 1: + print_help() + exit(2) + try: + opts, args = getopt.getopt(argv[1:], "h", ["test=", "test", "examples", "tck"]) + except getopt.GetoptError as err: + print(str(err)) + print_help() + exit(2) + else: + + stdout.write("Using python version:\n") + runcommand('python --version') + runcommand('pip install --upgrade -r ./test_requirements.txt') + retcode = 0 + + register(neorun, '--stop=' + NEO4J_HOME) + neorun('--start=' + NEO4J_HOME + ' -v 3.0.1 -p password') + for opt, arg in opts: + if opt == '-h': + print_help() + retcode = 2 + + elif opt == "--test": + retcode = retcode or runcommand(UNITTEST_RUNNER + "test") + elif opt == "--test=": + retcode = retcode or runcommand(UNITTEST_RUNNER + arg) + elif opt == "--example": + retcode = retcode or runcommand(UNITTEST_RUNNER + "examples") + elif opt == "--tck": + retcode = runcommand('coverage report --show-missing') or\ + runcommands(["python", "-c", "from test.tck.configure_feature_files import *; set_up()"]) or\ + runcommand(BEHAVE_RUNNER) or\ + runcommands(["python", "-c", "from test.tck.configure_feature_files import *; clean_up()"]) + + if retcode != 0: + break + + return retcode + + +def print_help(): + print(__doc__) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/runtests.sh b/runtests.sh deleted file mode 100755 index 89aa15b5b..000000000 --- a/runtests.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2002-2016 "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) - -NEORUN_OPTIONS="" -RUNNING=0 -QUICK=0 -KNOWN_HOSTS="${HOME}/.neo4j/known_hosts" -KNOWN_HOSTS_BACKUP="${KNOWN_HOSTS}.backup" - -FG_BRIGHT_RED='\033[1;31m' -FG_DEFAULT='\033[0m' - -# Parse options -while getopts ":dqr" OPTION -do - case ${OPTION} in - d) - NEORUN_OPTIONS="-f" - ;; - q) - QUICK=1 - ;; - r) - RUNNING=1 - ;; - \?) - echo "Invalid option: -${OPTARG}" >&2 - ;; - esac -done -shift $(($OPTIND - 1)) - -if [ -z "${TEAMCITY_VERSION}" ] -then - UNITTEST="unittest" -else - UNITTEST="teamcity.unittestpy" -fi - -if [ -z "${TEST}" ] -then - TEST="test" -fi - -VERSIONS=$* -if [ "${VERSIONS}" == "" ] -then - VERSIONS="nightly" -fi - -function check_exit_status { - EXIT_STATUS=$1 - if [ ${EXIT_STATUS} -ne 0 ] - then - echo "" - echo -e "${FG_BRIGHT_RED}Tests failed with status ${EXIT_STATUS}${FG_DEFAULT}" - exit ${EXIT_STATUS} - fi -} - -# Run tests -echo "Using $(python --version)" -pip install --upgrade -r ${DRIVER_HOME}/test_requirements.txt -echo "" - -TEST_RUNNER="coverage run -m ${UNITTEST} discover -vfs ${TEST}" -EXAMPLES_RUNNER="coverage run -m ${UNITTEST} discover -vfs examples" -BEHAVE_RUNNER="behave --tags=-db --tags=-tls --tags=-fixed_session_pool test/tck" - -if [ ${RUNNING} -eq 1 ] -then - ${TEST_RUNNER} - check_exit_status $? -else - export NEO4J_PASSWORD="password" - - echo "Running unit tests" - neokit/neorun ${NEORUN_OPTIONS} "${TEST_RUNNER}" ${VERSIONS} - check_exit_status $? - - if [ ${QUICK} -eq 0 ] - then - echo "Testing example code" - neokit/neorun ${NEORUN_OPTIONS} "${EXAMPLES_RUNNER}" ${VERSIONS} - check_exit_status $? - - echo "Testing TCK" - coverage report --show-missing - python -c 'from test.tck.configure_feature_files import *; set_up()' - echo "Feature files downloaded" - neokit/neorun ${NEORUN_OPTIONS} "${BEHAVE_RUNNER}" ${VERSIONS} - python -c 'from test.tck.configure_feature_files import *; clean_up()' - echo "Feature files removed" - - fi - -fi \ No newline at end of file From 3548fed1e8ca45f79eefccf6c7894bb9539bd743 Mon Sep 17 00:00:00 2001 From: Zhen Date: Wed, 25 May 2016 11:29:52 +0200 Subject: [PATCH 2/4] Changed password from password to neo4j Enabled runtests script to accept neorun.start args so that we could change version for running tests against 3.1 server Fixed the bug in runtests script where it cannot accept `test=name` to run a single unit test --- examples/test_examples.py | 14 +++++++------- neokit | 2 +- runtests.py | 23 ++++++++++++++++------- test/tck/steps/driver_auth_steps.py | 2 +- test/tck/tck_util.py | 2 +- test/test_session.py | 2 +- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/examples/test_examples.py b/examples/test_examples.py index be2a1c3ef..46fed58b5 100644 --- a/examples/test_examples.py +++ b/examples/test_examples.py @@ -32,7 +32,7 @@ # (* "good reason" is defined as knowing what you are doing) -auth_token = basic_auth("neo4j", "password") +auth_token = basic_auth("neo4j", "neo4j") class FreshDatabaseTestCase(ServerTestCase): @@ -48,7 +48,7 @@ class MinimalWorkingExampleTestCase(FreshDatabaseTestCase): def test_minimal_working_example(self): # tag::minimal-example[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password")) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j")) session = driver.session() session.run("CREATE (a:Person {name:'Arthur', title:'King'})") @@ -65,33 +65,33 @@ class ExamplesTestCase(FreshDatabaseTestCase): def test_construct_driver(self): # tag::construct-driver[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password")) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j")) # end::construct-driver[] return driver def test_configuration(self): # tag::configuration[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), max_pool_size=10) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), max_pool_size=10) # end::configuration[] return driver @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tls_require_encryption(self): # tag::tls-require-encryption[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), encrypted=True) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True) # end::tls-require-encryption[] @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tls_trust_on_first_use(self): # tag::tls-trust-on-first-use[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), encrypted=True, trust=TRUST_ON_FIRST_USE) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True, trust=TRUST_ON_FIRST_USE) # end::tls-trust-on-first-use[] assert driver @skip("testing verified certificates not yet supported ") def test_tls_signed(self): # tag::tls-signed[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES) + driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES) # end::tls-signed[] assert driver diff --git a/neokit b/neokit index 60cac056f..03df88a9b 160000 --- a/neokit +++ b/neokit @@ -1 +1 @@ -Subproject commit 60cac056f07bc63d02121e3908315962e0746caf +Subproject commit 03df88a9b5fc5f4b3ab651d895ac0a1ff7c3f3b3 diff --git a/runtests.py b/runtests.py index dfc301d22..350a85be3 100644 --- a/runtests.py +++ b/runtests.py @@ -20,13 +20,15 @@ """ Usage: runtests.py + -h : show this help message --test=name : run this specific test - --test : run all unit tests + --tests : run all unit tests --examples : run all example tests --tck : run tck tests - -h : show this help message + --neorun.start.args : args to neorun script example: - python ./runtests.py --test --examples --tck + python ./runtests.py --tests --examples --tck + python ./runtests.py --tests --examples --tck --neorun.start.args="-n 3.1 -p neo4j" """ from sys import argv, stdout, exit from os import name, path @@ -38,7 +40,7 @@ BEHAVE_RUNNER="behave --tags=-db --tags=-tls --tags=-fixed_session_pool test/tck" NEORUN_PATH = path.abspath('./neokit/neorun.py') -NEO4J_HOME = path.abspath('./resources/neo4jhome') +NEO4J_HOME = path.abspath('./build/neo4jhome') is_windows = (name == 'nt') @@ -73,7 +75,7 @@ def main(): print_help() exit(2) try: - opts, args = getopt.getopt(argv[1:], "h", ["test=", "test", "examples", "tck"]) + opts, args = getopt.getopt(argv[1:], "h", ["test=", "tests", "examples", "tck", "neorun.start.args="]) except getopt.GetoptError as err: print(str(err)) print_help() @@ -86,13 +88,20 @@ def main(): retcode = 0 register(neorun, '--stop=' + NEO4J_HOME) - neorun('--start=' + NEO4J_HOME + ' -v 3.0.1 -p password') + + neorun_args = '-p neo4j' + for opt, arg in opts: + if opt == '--neorun.start.args': + neorun_args = arg + break + neorun('--start=' + NEO4J_HOME + ' ' + neorun_args) + for opt, arg in opts: if opt == '-h': print_help() retcode = 2 - elif opt == "--test": + elif opt == "--tests": retcode = retcode or runcommand(UNITTEST_RUNNER + "test") elif opt == "--test=": retcode = retcode or runcommand(UNITTEST_RUNNER + arg) diff --git a/test/tck/steps/driver_auth_steps.py b/test/tck/steps/driver_auth_steps.py index 0eaa1dffd..edc9d266a 100644 --- a/test/tck/steps/driver_auth_steps.py +++ b/test/tck/steps/driver_auth_steps.py @@ -30,7 +30,7 @@ def step_impl(context): @given("a driver is configured with auth enabled and correct password is provided") def step_impl(context): - context.driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), encrypted=False) + context.driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=False) @given("a driver is configured with auth enabled and the wrong password is provided") diff --git a/test/tck/tck_util.py b/test/tck/tck_util.py index 57144ab21..063e0635f 100644 --- a/test/tck/tck_util.py +++ b/test/tck/tck_util.py @@ -23,7 +23,7 @@ from test.tck.test_value import TestValue from test.tck.resultparser import parse_values_to_comparable -driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"), encrypted=False) +driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=False) runners = [] diff --git a/test/test_session.py b/test/test_session.py index d421aafb3..91f609344 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -33,7 +33,7 @@ from test.util import ServerTestCase -auth_token = basic_auth("neo4j", "password") +auth_token = basic_auth("neo4j", "neo4j") from neo4j.v1.exceptions import ProtocolError From 98066c2bdce6d62cfe3657999d5ba8c0640badc6 Mon Sep 17 00:00:00 2001 From: Zhen Date: Wed, 25 May 2016 11:56:53 +0200 Subject: [PATCH 3/4] Added runtests.sh back to simplify running process on linux machines. Fixed the bug with python v3+ about stdout.write writing bytes type data --- neokit | 2 +- runtests.py | 10 +++++++--- runtests.sh | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100755 runtests.sh diff --git a/neokit b/neokit index 03df88a9b..46d804137 160000 --- a/neokit +++ b/neokit @@ -1 +1 @@ -Subproject commit 03df88a9b5fc5f4b3ab651d895ac0a1ff7c3f3b3 +Subproject commit 46d80413782e08338d6747f25508ea94bcd1c7c2 diff --git a/runtests.py b/runtests.py index 350a85be3..cc002a70f 100644 --- a/runtests.py +++ b/runtests.py @@ -30,7 +30,7 @@ python ./runtests.py --tests --examples --tck python ./runtests.py --tests --examples --tck --neorun.start.args="-n 3.1 -p neo4j" """ -from sys import argv, stdout, exit +from sys import argv, stdout, exit, version_info from os import name, path from atexit import register import subprocess @@ -61,8 +61,12 @@ def run0(commands): p = subprocess.Popen(commands, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() retcode = p.wait() - stdout.write(out) - stdout.write(err) + if version_info < (3, 0): + stdout.write(out) + stdout.write(err) + else: + stdout.write(out.decode(stdout.encoding)) + stdout.write(err.decode(stdout.encoding)) return retcode diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 000000000..be32af5f3 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Copyright (c) 2002-2016 "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. + +if [ "$1" == "" ]; then + python ./runtests.py --tests --examples --tck +else + #Example: python ./runtests.py --tests --examples --tck --neorun.start.args=ā€-n 3.1 -p neo4jā€ + python ./runtests.py --tests --examples --tck --neorun.start.args=\""$1"\" +fi From eb2ed22a73714b36d9d48dd3675582b80c711e55 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Wed, 25 May 2016 15:41:26 +0200 Subject: [PATCH 4/4] Fixed a few bugs in runtests.py for running python commands on windows To run runtests.py on windows, we need to add python.exe to windows PATH var To run with different python versions, one way to do it is to update PATH var before calling runtests.py --- neokit | 2 +- runtests.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/neokit b/neokit index 46d804137..3ab3ec582 160000 --- a/neokit +++ b/neokit @@ -1 +1 @@ -Subproject commit 46d80413782e08338d6747f25508ea94bcd1c7c2 +Subproject commit 3ab3ec582936ef3329c51c6f9a891147287230cd diff --git a/runtests.py b/runtests.py index cc002a70f..a3c25e402 100644 --- a/runtests.py +++ b/runtests.py @@ -45,6 +45,13 @@ is_windows = (name == 'nt') +def runpymodule(command): + commands = command.split() + if is_windows: + commands = ['powershell.exe', 'python', '-m'] + commands + return run0(commands) + + def runcommand(command): commands = command.split() return runcommands(commands) @@ -88,7 +95,7 @@ def main(): stdout.write("Using python version:\n") runcommand('python --version') - runcommand('pip install --upgrade -r ./test_requirements.txt') + runpymodule('pip install --upgrade -r ./test_requirements.txt') retcode = 0 register(neorun, '--stop=' + NEO4J_HOME) @@ -106,16 +113,16 @@ def main(): retcode = 2 elif opt == "--tests": - retcode = retcode or runcommand(UNITTEST_RUNNER + "test") + retcode = retcode or runpymodule(UNITTEST_RUNNER + "test") elif opt == "--test=": - retcode = retcode or runcommand(UNITTEST_RUNNER + arg) + retcode = retcode or runpymodule(UNITTEST_RUNNER + arg) elif opt == "--example": - retcode = retcode or runcommand(UNITTEST_RUNNER + "examples") + retcode = retcode or runpymodule(UNITTEST_RUNNER + "examples") elif opt == "--tck": - retcode = runcommand('coverage report --show-missing') or\ - runcommands(["python", "-c", "from test.tck.configure_feature_files import *; set_up()"]) or\ - runcommand(BEHAVE_RUNNER) or\ - runcommands(["python", "-c", "from test.tck.configure_feature_files import *; clean_up()"]) + retcode = runpymodule('coverage report --show-missing') or \ + runcommands(["python", "-c", "\"from test.tck.configure_feature_files import *; set_up()\""]) or \ + runpymodule(BEHAVE_RUNNER) or \ + runcommands(["python", "-c", "\"from test.tck.configure_feature_files import *; clean_up()\""]) if retcode != 0: break