Skip to content

Commit 8924a5e

Browse files
authored
Merge pull request #143 from readthedocs/humitos/test-command-versions
2 parents 89bb0b6 + 3db2351 commit 8924a5e

File tree

5 files changed

+207
-2
lines changed

5 files changed

+207
-2
lines changed

.travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ env:
77
- PIPENV_IGNORE_VIRTUALENVS=1
88
before_install:
99
- pip install pipenv
10+
- docker pull readthedocs/build:master || true
1011
install:
1112
- pipenv install
1213
script:
13-
- pipenv run pytest --suppress-no-test-exit-code
14-
- docker build .
14+
- docker build --cache-from readthedocs/build:master -t readthedocs/build:master .
15+
- pipenv run pytest -m image_master
1516

1617
branches:
1718
only:
1819
- master
20+
- releases/5.x
21+
- releases/6.x
22+
- releases/7.x
23+
- releases/8.x

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ name = "pypi"
1111
requests = "*"
1212
pytest = "*"
1313
pytest-custom-exit-code = "*"
14+
docker = "*"

tests/__init__.py

Whitespace-only changes.

tests/test_versions.py

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import pytest
2+
from docker import APIClient
3+
4+
from .utils import run_command_in_container
5+
6+
7+
@pytest.mark.image_master
8+
@pytest.mark.parametrize(
9+
'command,expected_output',
10+
[
11+
# python
12+
('python2 --version', 'Python 2.7.18'),
13+
('python3.5 --version', 'Python 3.5.10'),
14+
('python3.6 --version', 'Python 3.6.12'),
15+
('python3.7 --version', 'Python 3.7.9'),
16+
('python3.8 --version', 'Python 3.8.6'),
17+
('pypy3.5 --version', 'Python 3.5.3 (928a4f70d3de7d17449456946154c5da6e600162, Feb 09 2019, 11:50:43)\n[PyPy 7.0.0 with GCC 8.2.0]'),
18+
# pip
19+
('python2 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pip (python 2.7)"),
20+
('python3.5 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.5.10/lib/python3.5/site-packages/pip (python 3.5)"),
21+
('python3.6 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/pip (python 3.6)"),
22+
('python3.7 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pip (python 3.7)"),
23+
('python3.8 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pip (python 3.8)"),
24+
# setuptools
25+
('python2 -c "import setuptools; print(setuptools.__version__)"', "44.0.0"),
26+
('python3.5 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
27+
('python3.6 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
28+
('python3.7 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
29+
('python3.8 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
30+
# virtualenv
31+
('python2 -m virtualenv --version', '16.7.9'),
32+
('python3.5 -m virtualenv --version', '16.7.9'),
33+
('python3.6 -m virtualenv --version', '16.7.9'),
34+
('python3.7 -m virtualenv --version', '16.7.9'),
35+
('python3.8 -m virtualenv --version', '16.7.9'),
36+
# others
37+
('node --version', 'v10.19.0'),
38+
('npm --version', '6.14.4'),
39+
('conda --version', 'conda 4.6.14'),
40+
('cargo --version', 'cargo 1.46.0 (149022b1d 2020-07-17)'),
41+
('git --version', 'git version 2.25.1'),
42+
]
43+
)
44+
def test_command_versions_image_master(command, expected_output):
45+
cmd_output = run_command_in_container('readthedocs/build:master', command)
46+
assert cmd_output == expected_output
47+
48+
49+
@pytest.mark.image_70
50+
@pytest.mark.parametrize(
51+
'command,expected_output',
52+
[
53+
# python
54+
('python2 --version', 'Python 2.7.18'),
55+
('python3.5 --version', 'Python 3.5.10'),
56+
('python3.6 --version', 'Python 3.6.12'),
57+
('python3.7 --version', 'Python 3.7.9'),
58+
('python3.8 --version', 'Python 3.8.6'),
59+
('pypy3.5 --version', 'Python 3.5.3 (928a4f70d3de7d17449456946154c5da6e600162, Feb 09 2019, 11:50:43)\n[PyPy 7.0.0 with GCC 8.2.0]'),
60+
# pip
61+
('python2 -m pip --version', "pip 20.0.2 from /home/docs/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pip (python 2.7)"),
62+
('python3.5 -m pip --version', "pip 20.0.2 from /home/docs/.pyenv/versions/3.5.10/lib/python3.5/site-packages/pip (python 3.5)"),
63+
('python3.6 -m pip --version', "pip 20.0.2 from /home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/pip (python 3.6)"),
64+
('python3.7 -m pip --version', "pip 20.0.2 from /home/docs/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pip (python 3.7)"),
65+
('python3.8 -m pip --version', "pip 20.0.2 from /home/docs/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pip (python 3.8)"),
66+
# setuptools
67+
('python2 -c "import setuptools; print(setuptools.__version__)"', "44.0.0"),
68+
('python3.5 -c "import setuptools; print(setuptools.__version__)"', "45.2.0"),
69+
('python3.6 -c "import setuptools; print(setuptools.__version__)"', "45.2.0"),
70+
('python3.7 -c "import setuptools; print(setuptools.__version__)"', "45.2.0"),
71+
('python3.8 -c "import setuptools; print(setuptools.__version__)"', "45.2.0"),
72+
# virtualenv
73+
('python2 -m virtualenv --version', 'virtualenv 20.0.7 from /home/docs/.pyenv/versions/2.7.18/lib/python2.7/site-packages/virtualenv/__init__.pyc'),
74+
('python3.5 -m virtualenv --version', 'virtualenv 20.0.7 from /home/docs/.pyenv/versions/3.5.10/lib/python3.5/site-packages/virtualenv/__init__.pyc'),
75+
('python3.6 -m virtualenv --version', 'virtualenv 20.0.7 from /home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/virtualenv/__init__.pyc'),
76+
('python3.7 -m virtualenv --version', 'virtualenv 20.0.7 from /home/docs/.pyenv/versions/3.7.9/lib/python3.7/site-packages/virtualenv/__init__.pyc'),
77+
('python3.8 -m virtualenv --version', 'virtualenv 20.0.7 from /home/docs/.pyenv/versions/3.8.6/lib/python3.8/site-packages/virtualenv/__init__.pyc'),
78+
# others
79+
('node --version', 'v8.10.0'),
80+
('npm --version', '3.5.2'),
81+
('conda --version', 'conda 4.6.14'),
82+
('cargo --version', 'cargo 1.46.0 (149022b1d 2020-07-17)'),
83+
('git --version', 'git version 2.17.1'),
84+
]
85+
)
86+
def test_command_versions_image_70(command, expected_output):
87+
cmd_output = run_command_in_container('readthedocs/build:7.0', command)
88+
assert cmd_output == expected_output
89+
90+
91+
@pytest.mark.image_60
92+
@pytest.mark.parametrize(
93+
'command,expected_output',
94+
[
95+
# python
96+
('python2 --version', 'Python 2.7.18'),
97+
('python3.5 --version', 'Python 3.5.10'),
98+
('python3.6 --version', 'Python 3.6.12'),
99+
('python3.7 --version', 'Python 3.7.9'),
100+
('python3.8 --version', 'Python 3.8.6'),
101+
('pypy3.5 --version', 'Python 3.5.3 (928a4f70d3de7d17449456946154c5da6e600162, Feb 09 2019, 11:50:43)\n[PyPy 7.0.0 with GCC 8.2.0]'),
102+
# pip
103+
('python2 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pip (python 2.7)"),
104+
('python3.5 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.5.10/lib/python3.5/site-packages/pip (python 3.5)"),
105+
('python3.6 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/pip (python 3.6)"),
106+
('python3.7 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pip (python 3.7)"),
107+
('python3.8 -m pip --version', "pip 20.0.1 from /home/docs/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pip (python 3.8)"),
108+
# setuptools
109+
('python2 -c "import setuptools; print(setuptools.__version__)"', "44.0.0"),
110+
('python3.5 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
111+
('python3.6 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
112+
('python3.7 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
113+
('python3.8 -c "import setuptools; print(setuptools.__version__)"', "45.1.0"),
114+
# virtualenv
115+
('python2 -m virtualenv --version', '16.7.9'),
116+
('python3.5 -m virtualenv --version', '16.7.9'),
117+
('python3.6 -m virtualenv --version', '16.7.9'),
118+
('python3.7 -m virtualenv --version', '16.7.9'),
119+
('python3.8 -m virtualenv --version', '16.7.9'),
120+
# others
121+
('node --version', 'v8.10.0'),
122+
('npm --version', '3.5.2'),
123+
('conda --version', 'conda 4.6.14'),
124+
('git --version', 'git version 2.17.1'),
125+
]
126+
)
127+
def test_command_versions_image_60(command, expected_output):
128+
cmd_output = run_command_in_container('readthedocs/build:6.0', command)
129+
assert cmd_output == expected_output
130+
131+
132+
@pytest.mark.image_50
133+
@pytest.mark.parametrize(
134+
'command,expected_output',
135+
[
136+
# python
137+
('python2 --version', 'Python 2.7.18'),
138+
('python3.6 --version', 'Python 3.6.12'),
139+
('python3.7 --version', 'Python 3.7.9'),
140+
('pypy3.5 --version', 'Python 3.5.3 (928a4f70d3de7d17449456946154c5da6e600162, Feb 09 2019, 11:50:43)\n[PyPy 7.0.0 with GCC 8.2.0]'),
141+
# pip
142+
('python2 -m pip --version', "pip 19.1.1 from /home/docs/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pip (python 2.7)"),
143+
('python3.6 -m pip --version', "pip 19.1.1 from /home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/pip (python 3.6)"),
144+
('python3.7 -m pip --version', "pip 19.1.1 from /home/docs/.pyenv/versions/3.7.9/lib/python3.7/site-packages/pip (python 3.7)"),
145+
# setuptools
146+
('python2 -c "import setuptools; print(setuptools.__version__)"', "41.0.1"),
147+
('python3.6 -c "import setuptools; print(setuptools.__version__)"', "41.0.1"),
148+
('python3.7 -c "import setuptools; print(setuptools.__version__)"', "41.0.1"),
149+
# virtualenv
150+
('python2 -m virtualenv --version', '16.6.0'),
151+
('python3.6 -m virtualenv --version', '16.6.0'),
152+
('python3.7 -m virtualenv --version', '16.6.0'),
153+
# others
154+
('node --version', 'v8.10.0'),
155+
('npm --version', '3.5.2'),
156+
('conda --version', 'conda 4.6.14'),
157+
('git --version', 'git version 2.17.1'),
158+
]
159+
)
160+
def test_command_versions_image_50(command, expected_output):
161+
cmd_output = run_command_in_container('readthedocs/build:5.0', command)
162+
assert cmd_output == expected_output

tests/utils.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from docker import APIClient
2+
3+
4+
def run_command_in_container(container_image, command):
5+
client = APIClient()
6+
7+
# Create the container
8+
container = client.create_container(
9+
image=container_image,
10+
command=(
11+
'/bin/sh -c "sleep {time}; exit {exit}"'.format(
12+
time=60,
13+
exit=42,
14+
)
15+
),
16+
detach=True,
17+
user='docs',
18+
)
19+
20+
# Start the container
21+
container_id = container.get('Id')
22+
client.start(container=container_id)
23+
24+
# Execute commands to verify versions
25+
exec_cmd = client.exec_create(
26+
container=container_id,
27+
cmd=f"/bin/sh -c '{command}'",
28+
stdout=True,
29+
stderr=True,
30+
)
31+
cmd_output = client.exec_start(exec_id=exec_cmd['Id'], stream=False)
32+
cmd_output = cmd_output.decode('utf-8', 'replace').strip()
33+
34+
# Kill container
35+
client.kill(container_id)
36+
37+
return cmd_output

0 commit comments

Comments
 (0)