Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 1d2df4d

Browse files
authored
CI: use circleci (#76)
- Replace travis with circleci - Update the drivers to its latest versions - Update selenium pytest - Test with more versions of sphinx and python - Inject the extra js data before the head tag, as latest versions of sphinx don't inject jquery with the tag that the test was using. - Fix tests for firefox (this test has always been failing for me locally before moving to circle) The problem with the test was that it was assuming that the inner real width/height was the same the given by the test, but this doesn't count with extra space generated for window borders, navigation bar, etc (`set_viewport_size` uses this too). This was failing only for firefox. Also, the current test was just assuming the margins were the same size (dividing by 2), instead I'm just checking that the margins are almost the same size (since we want to check that the modal is in the middle).
1 parent 1ce5790 commit 1d2df4d

File tree

7 files changed

+99
-55
lines changed

7 files changed

+99
-55
lines changed

.circleci/config.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: 2.1
2+
3+
orbs:
4+
browser-tools: circleci/[email protected]
5+
6+
commands:
7+
run-tox:
8+
description: "Run tox"
9+
parameters:
10+
version:
11+
type: string
12+
sphinx-version:
13+
type: string
14+
default: "1,2,3,latest"
15+
steps:
16+
- browser-tools/install-browser-tools
17+
- checkout
18+
- run: pip install --user tox
19+
- run:
20+
name: Test with Chrome driver
21+
command: tox -e "<<parameters.version>>-sphinx{<<parameters.sphinx-version>>}" -- --driver Chrome
22+
- run:
23+
name: Test with Firefox driver
24+
command: tox -e "<<parameters.version>>-sphinx{<<parameters.sphinx-version>>}" -- --driver Firefox
25+
26+
jobs:
27+
py36:
28+
docker:
29+
- image: 'cimg/python:3.6-browsers'
30+
steps:
31+
- run-tox:
32+
version: py36
33+
py37:
34+
docker:
35+
- image: 'cimg/python:3.7-browsers'
36+
steps:
37+
- run-tox:
38+
version: py37
39+
py38:
40+
docker:
41+
- image: 'cimg/python:3.8-browsers'
42+
steps:
43+
- run-tox:
44+
version: py38
45+
py39:
46+
docker:
47+
- image: 'cimg/python:3.9-browsers'
48+
steps:
49+
- run-tox:
50+
version: py39
51+
52+
workflows:
53+
version: 2
54+
tests:
55+
jobs:
56+
- py39
57+
- py38
58+
- py37
59+
- py36

.travis.yml

-23
This file was deleted.

scripts/setup_chromedriver.sh

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Get the latest version from https://sites.google.com/a/chromium.org/chromedriver/
2-
wget -N https://chromedriver.storage.googleapis.com/85.0.4183.83/chromedriver_linux64.zip -P ~/
2+
wget -N https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip -P ~/
33
unzip ~/chromedriver_linux64.zip -d ~/
44
rm ~/chromedriver_linux64.zip
55
sudo mv -f ~/chromedriver /usr/local/bin/

scripts/setup_geckodriver.sh

100644100755
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
wget -N https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz -P ~/
2-
tar xvzf ~/geckodriver-v0.24.0-linux64.tar.gz -C ~/
3-
rm ~/geckodriver-v0.24.0-linux64.tar.gz
1+
VERSION=v0.28.0
2+
wget -N https://github.com/mozilla/geckodriver/releases/download/${VERSION}/geckodriver-${VERSION}-linux64.tar.gz -P ~/
3+
tar xvzf ~/geckodriver-${VERSION}-linux64.tar.gz -C ~/
4+
rm ~/geckodriver-${VERSION}-linux64.tar.gz
45
sudo mv -f ~/geckodriver /usr/local/bin/
56
sudo chmod +x /usr/local/bin/geckodriver

tests/test_ui.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""UI tests."""
22

3-
import os
43
import json
4+
import os
55
import time
66
from urllib import parse
77

8-
import pytest
98
import sphinx
9+
10+
import pytest
1011
from selenium import webdriver
1112
from selenium.webdriver.common.by import By
1213
from selenium.webdriver.common.keys import Keys
1314
from selenium.webdriver.support import expected_conditions as EC
1415
from selenium.webdriver.support.ui import WebDriverWait
15-
16-
from tests.utils import InjectJsManager, set_viewport_size, get_ajax_overwrite_func
1716
from tests import TEST_DOCS_SRC
18-
17+
from tests.utils import (InjectJsManager, get_ajax_overwrite_func,
18+
set_viewport_size)
1919

2020
READTHEDOCS_DATA = {
2121
'project': 'docs',
@@ -556,24 +556,28 @@ def test_position_search_modal(selenium, app, status, warning):
556556
(1920, 1080),
557557
]
558558

559-
for window_size in window_sizes:
560-
set_viewport_size(selenium, *window_size)
559+
for width, height in window_sizes:
560+
set_viewport_size(driver=selenium, width=width, height=height)
561561
modal_location = search_outer.location
562562
modal_size = search_outer.size
563563

564+
inner_width, inner_height = selenium.execute_script(
565+
"return [window.innerWidth, window.innerHeight];"
566+
)
567+
564568
# checking for horizontal position
565-
calculated_x = (window_size[0] - modal_size['width'])/2
566-
actual_x = modal_location['x']
569+
right = inner_width - (modal_size['width'] + modal_location['x'])
570+
left = inner_width - (modal_size['width'] + right)
567571
assert (
568-
abs(actual_x - calculated_x) < 10
569-
), f'difference between calculated and actual x coordinate should not be greater than 10 pixels for {"x".join(map(str, window_size))}'
572+
right == pytest.approx(left, 1)
573+
), f'Vertical margins should be the same size for {width}x{height} ({left} / {right}).'
570574

571575
# checking for vertical position
572-
calculated_y = (window_size[1] - modal_size['height'])/2
573-
actual_y = modal_location['y']
576+
bottom = inner_height - (modal_size['height'] + modal_location['y'])
577+
top = inner_height - (modal_size['height'] + bottom)
574578
assert (
575-
abs(actual_y - calculated_y) < 10
576-
), f'difference between calculated and actual y coordinate should not be greater than 10 pixels for {"x".join(map(str, window_size))}'
579+
top == pytest.approx(bottom, 1)
580+
), f'Horizontal margins should be the same size for {width}x{height} ({top} / {bottom}).'
577581

578582

579583
@pytest.mark.sphinx(srcdir=TEST_DOCS_SRC)

tests/utils.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class InjectJsManager:
1212
"""
1313
Context manager for injected script tag.
1414
15-
This will insert ``html_tag`` after the script tag which inserts
16-
jquery.js to the file which is passed when entered.
17-
And it will remove that line when exiting from it.
15+
This will insert ``html_tag`` at the bottom of the <head> tag
16+
in the file which is passed when entered.
17+
And it will restore its original content when exiting.
1818
"""
1919
def __init__(self, file, html_tag):
2020
self._file = file
@@ -25,8 +25,9 @@ def __enter__(self):
2525
with open(self._file, 'r+') as f:
2626
self.old_content = f.read()
2727
new_content = self.old_content.replace(
28-
'<script type="text/javascript" src="_static/jquery.js"></script>',
29-
'<script type="text/javascript" src="_static/jquery.js"></script>' + self._script
28+
'</head>',
29+
self._script + '</head>',
30+
1,
3031
)
3132
f.seek(0)
3233
f.write(new_content)
@@ -43,8 +44,10 @@ def set_viewport_size(driver, width, height):
4344
"""Sets the viewport size to the given width and height."""
4445
window_size = driver.execute_script(
4546
"""
46-
return [window.outerWidth - window.innerWidth + arguments[0],
47-
window.outerHeight - window.innerHeight + arguments[1]];
47+
return [
48+
window.outerWidth - window.innerWidth + arguments[0],
49+
window.outerHeight - window.innerHeight + arguments[1]
50+
];
4851
""",
4952
width,
5053
height

tox.ini

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[tox]
22
minversion = 3.10
33
envlist =
4-
py{36,37}-sphinx{18}
5-
py{36,37}-sphinx{20,21}
4+
py{36,37,38,39}-sphinx{1,2,3,latest}
65
docs
76
skipsdist = True
87

98
[testenv]
109
description = run the whole test suite
1110
deps =
1211
.
13-
pytest-selenium==1.17.0
14-
sphinx18: Sphinx<1.9
15-
sphinx20: Sphinx<2.1
16-
sphinx21: Sphinx<2.2
12+
pytest-selenium==2.0.1
13+
sphinx1: Sphinx<2.0
14+
sphinx2: Sphinx<3.0
15+
sphinx3: Sphinx<4.0
16+
sphinxlatest: Sphinx
1717
commands = pytest {posargs}
1818

1919
[testenv:docs]

0 commit comments

Comments
 (0)