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