Skip to content

Commit ab2b407

Browse files
committed
Integrate travis CI
1 parent a45574b commit ab2b407

6 files changed

Lines changed: 116 additions & 10 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ venv
1616

1717
# pytest report
1818
test-report.html
19-
assets/
19+
assets/
20+
.coverage
21+
22+
# browser trash
23+
geckodriver.log

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
language: python
2+
python:
3+
- "3.6"
4+
- "3.7"
5+
- "3.8"
6+
addons:
7+
apt:
8+
update: true
9+
before_install:
10+
# Install dependencies
11+
- sudo apt-get install -y chromium-browser
12+
# Install ChromeDriver (64bits; replace 64 with 32 for 32bits).
13+
- wget -N http://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip -P ~/
14+
- unzip ~/chromedriver_linux64.zip -d ~/
15+
- rm ~/chromedriver_linux64.zip
16+
- sudo mv -f ~/chromedriver /usr/local/share/
17+
- sudo chmod +x /usr/local/share/chromedriver
18+
- sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
19+
install:
20+
- pip install --no-cache-dir --upgrade pip
21+
- pip install -r requirements.txt
22+
script:
23+
- whereis google-chrome-stable
24+
- whereis chromedriver
25+
- ./run-code-analysis.sh
26+
after_success:
27+
- coveralls
28+
notifications:
29+
email: false

run-code-analysis.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
declare -a RESULT
4+
5+
# specifies a set of variables to declare CLI output color
6+
FAILED_OUT="\033[0;31m"
7+
PASSED_OUT="\033[0;32m"
8+
NONE_OUT="\033[0m"
9+
10+
# specifies a set of variables to declare files to be used for code assessment
11+
PROJECT_FILES="./"
12+
TESTS_FILES="tests"
13+
14+
15+
function store-failures {
16+
RESULT+=("$1")
17+
}
18+
19+
20+
function remove-pycache-trash {
21+
local PYCACHE_DIR="__pycache__"
22+
echo "Removing ${PYCACHE_DIR} directories if present ..."
23+
( find . -d -name ${PYCACHE_DIR} | xargs rm -r ) || echo -e "No ${PYCACHE_DIR} found"
24+
}
25+
26+
27+
function remove-analysis-trash {
28+
local PYTEST_CACHE_DIR='.pytest_cache'
29+
local MYPY_CACHE_DIR='.mypy_cache'
30+
echo "Removing code analysis trash if present ..."
31+
[[ -d "$PYTEST_CACHE_DIR" ]] && rm -rf ${PYTEST_CACHE_DIR} && echo "pytest trash is removed"
32+
[[ -d "$MYPY_CACHE_DIR" ]] && rm -rf ${MYPY_CACHE_DIR} && echo "mypy trash is removed"
33+
}
34+
35+
36+
function install-dependencies {
37+
echo "Installing python code analysis packages ..." \
38+
&& ( pip install --no-cache-dir --upgrade pip ) \
39+
&& ( pip install --no-cache-dir -r requirements.txt )
40+
}
41+
42+
43+
function run-unittests {
44+
echo "Running unittests ..." && ( pytest -m unittest )
45+
}
46+
47+
48+
function run-black-analysis() {
49+
echo "Running black analysis ..." && ( black --check "${PROJECT_FILES}" )
50+
}
51+
52+
53+
function run-code-analysis {
54+
echo "Running code analysis ..."
55+
remove-pycache-trash
56+
run-unittests || store-failures "Unittests are failed!"
57+
run-black-analysis || store-failures "black analysis is failed!"
58+
59+
if [[ ${#RESULT[@]} -ne 0 ]];
60+
then echo -e "${FAILED_OUT}Some errors occurred while analysing the code quality.${NONE_OUT}"
61+
for failed_item in "${RESULT[@]}"; do
62+
echo -e "${FAILED_OUT}- ${failed_item}${NONE_OUT}"
63+
done
64+
remove-analysis-trash
65+
exit 1
66+
fi
67+
remove-analysis-trash
68+
echo -e "${PASSED_OUT}Code analysis is passed${NONE_OUT}"
69+
}
70+
71+
72+
function main() {
73+
if [[ "$1" == "install-dependencies" ]];
74+
then install-dependencies || store-failures "Python packages installation is failed!";
75+
fi
76+
run-code-analysis
77+
}
78+
79+
80+
main "$@"

tests/coverage/markers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33

44
unittest: MarkDecorator = pytest.mark.unittest
55
smoke: MarkDecorator = pytest.mark.smoke
6-

tests/coverage/unittests/browsers/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def browser_factory(name: str) -> WebBrowser:
1919
return target
2020
if name == "FireFox":
2121
target = FireFox()
22+
return target
2223
raise WebBrowserError(f"Browser {name} is not supported!")
2324

2425
return browser_factory

tests/coverage/unittests/browsers/test_browsers.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
from typing import Callable
21
import pytest
32
from tests.coverage.markers import unittest
4-
from demo.browsers import WebBrowser, WebBrowserError
5-
6-
7-
@unittest
8-
@pytest.mark.parametrize("name", ["Chrome", "FireFox", "Safari"])
9-
def test_browser_name(browser: Callable[[str], WebBrowser], name: str) -> None:
10-
assert browser(name).name() == name
3+
from demo.browsers import WebBrowserError
114

125

136
@unittest

0 commit comments

Comments
 (0)