1+ #!/usr/bin/env python
2+ # -*- encoding: utf-8 -*-
3+
4+ # Copyright (c) 2002-2016 "Neo Technology,"
5+ # Network Engine for Objects in Lund AB [http://neotechnology.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+ Usage: runtests.py
23+ -h : show this help message
24+ --test=name : run this specific test
25+ --tests : run all unit tests
26+ --examples : run all example tests
27+ --tck : run tck tests
28+ --neorun.start.args : args to neorun script
29+ example:
30+ python ./runtests.py --tests --examples --tck
31+ python ./runtests.py --tests --examples --tck --neorun.start.args="-n 3.1 -p neo4j"
32+ """
33+ from sys import argv , stdout , exit , version_info
34+ from os import name , path
35+ from atexit import register
36+ import subprocess
37+ import getopt
38+
39+ UNITTEST_RUNNER = "coverage run -m unittest discover -vfs "
40+ BEHAVE_RUNNER = "behave --tags=-db --tags=-tls --tags=-fixed_session_pool test/tck"
41+
42+ NEORUN_PATH = path .abspath ('./neokit/neorun.py' )
43+ NEO4J_HOME = path .abspath ('./build/neo4jhome' )
44+
45+ is_windows = (name == 'nt' )
46+
47+
48+ def runpymodule (command ):
49+ commands = command .split ()
50+ if is_windows :
51+ commands = ['powershell.exe' , 'python' , '-m' ] + commands
52+ return run0 (commands )
53+
54+
55+ def runcommand (command ):
56+ commands = command .split ()
57+ return runcommands (commands )
58+
59+
60+ def runcommands (commands ):
61+ if is_windows :
62+ commands = ['powershell.exe' ] + commands
63+ return run0 (commands )
64+
65+
66+ def run0 (commands ):
67+ stdout .write ("Running commands: %s\n " % commands )
68+ p = subprocess .Popen (commands , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
69+ out , err = p .communicate ()
70+ retcode = p .wait ()
71+ if version_info < (3 , 0 ):
72+ stdout .write (out )
73+ stdout .write (err )
74+ else :
75+ stdout .write (out .decode (stdout .encoding ))
76+ stdout .write (err .decode (stdout .encoding ))
77+ return retcode
78+
79+
80+ def neorun (command ):
81+ runcommand ('python ' + NEORUN_PATH + ' ' + command )
82+
83+
84+ def main ():
85+ if len (argv ) <= 1 :
86+ print_help ()
87+ exit (2 )
88+ try :
89+ opts , args = getopt .getopt (argv [1 :], "h" , ["test=" , "tests" , "examples" , "tck" , "neorun.start.args=" ])
90+ except getopt .GetoptError as err :
91+ print (str (err ))
92+ print_help ()
93+ exit (2 )
94+ else :
95+
96+ stdout .write ("Using python version:\n " )
97+ runcommand ('python --version' )
98+ runpymodule ('pip install --upgrade -r ./test_requirements.txt' )
99+ retcode = 0
100+
101+ register (neorun , '--stop=' + NEO4J_HOME )
102+
103+ neorun_args = '-p neo4j'
104+ for opt , arg in opts :
105+ if opt == '--neorun.start.args' :
106+ neorun_args = arg
107+ break
108+ neorun ('--start=' + NEO4J_HOME + ' ' + neorun_args )
109+
110+ for opt , arg in opts :
111+ if opt == '-h' :
112+ print_help ()
113+ retcode = 2
114+
115+ elif opt == "--tests" :
116+ retcode = retcode or runpymodule (UNITTEST_RUNNER + "test" )
117+ elif opt == "--test=" :
118+ retcode = retcode or runpymodule (UNITTEST_RUNNER + arg )
119+ elif opt == "--example" :
120+ retcode = retcode or runpymodule (UNITTEST_RUNNER + "examples" )
121+ elif opt == "--tck" :
122+ retcode = runpymodule ('coverage report --show-missing' ) or \
123+ runcommands (["python" , "-c" , "\" from test.tck.configure_feature_files import *; set_up()\" " ]) or \
124+ runpymodule (BEHAVE_RUNNER ) or \
125+ runcommands (["python" , "-c" , "\" from test.tck.configure_feature_files import *; clean_up()\" " ])
126+
127+ if retcode != 0 :
128+ break
129+
130+ return retcode
131+
132+
133+ def print_help ():
134+ print (__doc__ )
135+
136+
137+ if __name__ == "__main__" :
138+ main ()
0 commit comments