Skip to content

Commit 7c57776

Browse files
committed
Improve TestKit glue
* add option to choose interpreter version * make Python invocations more strict (warnings as errors) * refactor and simplify code
1 parent 154054b commit 7c57776

File tree

6 files changed

+87
-27
lines changed

6 files changed

+87
-27
lines changed

testkit/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ RUN pyenv install 3.6.13
4444
RUN pyenv rehash
4545
RUN pyenv global 3.6.13
4646

47-
# Install Latest pip for each environment
47+
# Install Latest pip and setuptools for each environment
4848
# https://pip.pypa.io/en/stable/news/
4949
RUN python -m pip install --upgrade pip
50+
RUN python -m pip install --upgrade setuptools
5051

5152
# Install Python Testing Tools
5253
RUN python -m pip install coverage tox

testkit/_common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
6+
TEST_BACKEND_VERSION = os.getenv("TEST_BACKEND_VERSION", "python")
7+
8+
9+
def run(args, env=None):
10+
return subprocess.run(
11+
args, universal_newlines=True, stdout=sys.stdout, stderr=sys.stderr,
12+
check=True, env=env
13+
)
14+
15+
16+
def run_python(args, env=None):
17+
run([TEST_BACKEND_VERSION, "-W", "error", *args], env=env)

testkit/backend.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
import subprocess
2-
import sys
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) "Neo4j"
4+
# Neo4j Sweden AB [https://neo4j.com]
5+
#
6+
# This file is part of Neo4j.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# https://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
21+
from _common import run_python
22+
323

424
if __name__ == "__main__":
5-
subprocess.check_call(
6-
["python", "-W", "error", "-m", "testkitbackend"],
7-
stdout=sys.stdout, stderr=sys.stderr
8-
)
25+
run_python(["-m", "testkitbackend"])

testkit/build.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44
"""
55

66

7-
import subprocess
8-
import sys
9-
10-
11-
def run(args, env=None):
12-
subprocess.run(args, universal_newlines=True, stdout=sys.stdout,
13-
stderr=sys.stderr, check=True, env=env)
7+
from _common import run_python
148

159

1610
if __name__ == "__main__":
17-
run(["python", "setup.py", "build"])
18-
run(["python", "-m", "pip", "install", "-U", "pip"])
19-
run(["python", "-m", "pip", "install", "-Ur",
20-
"testkitbackend/requirements.txt"])
11+
run_python(["setup.py", "build"])
12+
run_python(["-m", "pip", "install", "-U", "pip"])
13+
run_python(["-m", "pip", "install", "-Ur",
14+
"testkitbackend/requirements.txt"])

testkit/integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) "Neo4j"
4+
# Neo4j Sweden AB [https://neo4j.com]
5+
#
6+
# This file is part of Neo4j.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# https://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
121
if __name__ == "__main__":
222
pass

testkit/unittests.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
import subprocess
2-
import sys
1+
#!/usr/bin/env python
32

3+
# Copyright (c) "Neo4j"
4+
# Neo4j Sweden AB [https://neo4j.com]
5+
#
6+
# This file is part of Neo4j.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# https://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
419

5-
def run(args):
6-
subprocess.run(
7-
args, universal_newlines=True, stdout=sys.stdout, stderr=sys.stderr,
8-
check=True
9-
)
20+
21+
from _common import run_python
1022

1123

1224
if __name__ == "__main__":
13-
run([
14-
"python", "-m", "tox", "-c", "tox-unit.ini"])
25+
run_python(["-m", "tox", "-c", "tox-unit.ini"])

0 commit comments

Comments
 (0)