Skip to content

Commit d7f8b16

Browse files
authored
Improve TestKit glue (#810)
* add option to choose interpreter version * make Python invocations more strict (warnings as errors) * refactor and simplify code * TestKit: install and test with Python 3.6-3.9
1 parent 154054b commit d7f8b16

File tree

7 files changed

+103
-36
lines changed

7 files changed

+103
-36
lines changed

testkit/Dockerfile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ RUN git clone https://github.com/pyenv/pyenv.git .pyenv
3939
ENV PYENV_ROOT /.pyenv
4040
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
4141

42-
# Set minimum supported Python version
43-
RUN pyenv install 3.6.13
44-
RUN pyenv rehash
45-
RUN pyenv global 3.6.13
46-
47-
# Install Latest pip for each environment
48-
# https://pip.pypa.io/en/stable/news/
49-
RUN python -m pip install --upgrade pip
42+
# Setup python version
43+
ENV PYTHON_VERSIONS 3.6 3.7 3.8 3.9
5044

51-
# Install Python Testing Tools
52-
RUN python -m pip install coverage tox
45+
RUN for version in $PYTHON_VERSIONS; do \
46+
pyenv install $version:latest; \
47+
done
48+
RUN pyenv rehash
49+
RUN pyenv global $(pyenv versions --bare --skip-aliases)
50+
51+
# Install Latest pip and setuptools for each environment
52+
# + tox and tools for starting the tests
53+
RUN for version in $PYTHON_VERSIONS; do \
54+
python$version -m pip install -U pip && \
55+
python$version -m pip install -U setuptools && \
56+
python$version -m pip install -U coverage tox; \
57+
done

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"])

tox-unit.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[tox]
22
envlist =
33
py36
4+
py37
5+
py38
6+
py39
47

58
[testenv]
69
deps =

0 commit comments

Comments
 (0)