Skip to content

Commit 32d8e16

Browse files
authored
Merge pull request #46 from eficode/feature/tests
Fixes tests, sets up CI
2 parents 04d3ebd + d659ce1 commit 32d8e16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+317
-142
lines changed

.github/workflows/tests.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Tests (Python 3.x)
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/**'
7+
- 'src/**'
8+
- 'tests/**'
9+
- 'setup.py'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/**'
13+
- 'src/**'
14+
- 'tests/**'
15+
- 'setup.py'
16+
jobs:
17+
test_using_builtin_python:
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ 'ubuntu-latest', 'windows-latest' ]
23+
python-version: [ '3.6', '3.7', '3.8' ]
24+
include:
25+
- os: ubuntu-latest
26+
set_display: export DISPLAY=:99; Xvfb :99 -screen 0 1024x768x24 -ac -noreset & sleep 3
27+
#- os: macos-latest
28+
#set_tmpdir: export TMPDIR=/tmp
29+
- os: windows-latest
30+
set_codepage: chcp 850
31+
32+
runs-on: ${{ matrix.os }}
33+
34+
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
35+
steps:
36+
- uses: actions/checkout@v2
37+
38+
- name: Setup python ${{ matrix.python-version }} for running the tests
39+
uses: actions/setup-python@v1
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
architecture: 'x64'
43+
44+
# pyautogui does not work by default (https://github.com/asweigart/pyautogui/issues/247)
45+
# need to disable security feature (https://apple.stackexchange.com/questions/178313/change-accessibility-setting-on-mac-using-terminal)
46+
# and database is readonly (https://github.com/jacobsalmela/tccutil/issues/18)
47+
# you need to disable SIP, but for that go into recovery mode and disable it - not on CI system
48+
#- name: Install test tools to Mac
49+
#run: |
50+
#sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'UPDATE access SET allowed = "1";'
51+
#if: runner.os == 'macOS'
52+
53+
- name: Install test tools to Linux
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get -y -q install xvfb scrot chromium-browser
57+
touch ~/.Xauthority
58+
if: contains(matrix.os, 'ubuntu')
59+
60+
- name: Install python test dependencies
61+
run: |
62+
python --version
63+
python -m pip install mock robotframework opencv-python eel .
64+
65+
- name: Run tests
66+
run: |
67+
${{ matrix.set_codepage }}
68+
${{ matrix.set_display }}
69+
python tests/utest/run_tests.py
70+
python tests/atest/run_tests.py
71+
72+
- name: Archive acceptances test results
73+
uses: actions/upload-artifact@v1.0.0
74+
with:
75+
name: log-${{ matrix.python-version }}-${{ matrix.os }}
76+
path: log.html
77+
if: always() && job.status == 'failure'
78+
79+
- name: Archive acceptances test failure screenshot on Linux
80+
uses: actions/upload-artifact@v1.0.0
81+
with:
82+
name: screenshot-${{ matrix.python-version }}-${{ matrix.os }}
83+
path: /tmp/Atest.Calculator-screenshot-1.png
84+
if: always() && job.status == 'failure' && contains(matrix.os, 'ubuntu')

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ log.html
66
*-screenshot-*.png
77
*\$py.class
88
*.swp
9-
*__pycache__
9+
*__pycache__
10+
/bin
11+
/include
12+
/lib

.travis.yml

-27
This file was deleted.

tests/atest/calculator.robot

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*** Settings ***
2+
Library ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${TEMPDIR}
3+
4+
*** Test cases ***
5+
6+
Calculator
7+
Set Confidence 0.9
8+
Launch application python tests/atest/calculator/calculator.py
9+
${location1}= Wait for inputs.png timeout=30
10+
Click to the above of ${location1} 20
11+
Type 1010
12+
Click to the below of ${location1} 20
13+
Type 1001
14+
${location2}= Locate or_button.png
15+
Click to the below of ${location2} 0
16+
Click to the below of ${location2} 50
17+
${result}= Copy
18+
Should be equal as integers ${result} 1011
19+
Click Image close_button.png
20+
[Teardown] Terminate application

tests/atest/calculator/calculator.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import eel
2+
import os
3+
import sys
4+
5+
6+
os.chdir(os.path.dirname(__file__))
7+
8+
eel.init('web')
9+
10+
11+
@eel.expose
12+
def close():
13+
sys.exit(0)
14+
15+
16+
eel.start('main.html', size=(300, 380))
167 KB
Binary file not shown.

tests/atest/calculator/web/main.html

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Bitwise Calculator</title>
5+
6+
<style>
7+
@font-face {
8+
font-family: Roboto;
9+
src: url('Roboto-Black.ttf') format('truetype');
10+
}
11+
12+
body {
13+
font-family: Roboto;
14+
font-size: 18px;
15+
}
16+
17+
.clickable {
18+
user-select: none;
19+
cursor: pointer;
20+
}
21+
22+
.button {
23+
background-color: black;
24+
color: white;
25+
padding: 10px 30px;
26+
margin: 10px;
27+
text-align: center;
28+
text-decoration: none;
29+
display: block;
30+
border: none;
31+
border-radius: 10px;
32+
}
33+
34+
.button:active {
35+
background-color: gray;
36+
}
37+
38+
.binary-input {
39+
border: 2px solid black;
40+
outline: none;
41+
}
42+
43+
#first,#second {
44+
padding: 10px;
45+
}
46+
47+
.check {
48+
color: gray;
49+
}
50+
51+
.check[checked] {
52+
color: black;
53+
}
54+
55+
#result {
56+
text-align: center;
57+
display: block;
58+
font-size: 24px;
59+
padding: 20px 0px;
60+
}
61+
</style>
62+
63+
<script type="text/javascript" src="/eel.js"></script>
64+
<script type="text/javascript">
65+
function setInputFilter(textbox, inputFilter) {
66+
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
67+
textbox.addEventListener(event, function() {
68+
if (inputFilter(this.value)) {
69+
this.oldValue = this.value;
70+
this.oldSelectionStart = this.selectionStart;
71+
this.oldSelectionEnd = this.selectionEnd;
72+
} else if (this.hasOwnProperty("oldValue")) {
73+
this.value = this.oldValue;
74+
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
75+
} else {
76+
this.value = "";
77+
}
78+
});
79+
});
80+
}
81+
82+
function selectElementText(el, win) {
83+
win = win || window;
84+
var doc = win.document, sel, range;
85+
if (win.getSelection && doc.createRange) {
86+
sel = win.getSelection();
87+
range = doc.createRange();
88+
range.selectNodeContents(el);
89+
sel.removeAllRanges();
90+
sel.addRange(range);
91+
} else if (doc.body.createTextRange) {
92+
range = doc.body.createTextRange();
93+
range.moveToElementText(el);
94+
range.select();
95+
}
96+
}
97+
98+
function main() {
99+
let checks = document.querySelectorAll('.check');
100+
checks.forEach(e => {
101+
e.addEventListener('click', event => {
102+
if (event.target.hasAttribute('checked')) {
103+
event.target.removeAttribute('checked');
104+
} else {
105+
event.target.setAttribute('checked', 1);
106+
}
107+
});
108+
});
109+
110+
let inputs = document.querySelectorAll('.binary-input');
111+
inputs.forEach(e => {
112+
setInputFilter(e, function(value) {
113+
return /^[01]+$/.test(value);
114+
});
115+
});
116+
117+
let close = document.querySelector('#close');
118+
close.addEventListener('click', event => {
119+
eel.close();
120+
window.close('','_parent','');
121+
});
122+
123+
let result = document.querySelector('#result');
124+
let resultArea = document.querySelector('#result-area');
125+
resultArea.addEventListener('click', event => {
126+
selectElementText(result);
127+
});
128+
129+
let fnot = document.querySelector('#fnot');
130+
let fnumber = document.querySelector('#fnumber');
131+
let snot = document.querySelector('#snot');
132+
let snumber = document.querySelector('#snumber');
133+
134+
let buttons = document.querySelectorAll('.button[operation]');
135+
buttons.forEach(e => {
136+
e.addEventListener('click', event => {
137+
138+
let fvalue = parseInt(fnumber.value, 2);
139+
if (fnot.hasAttribute('checked')) {
140+
fvalue = ~fvalue;
141+
}
142+
let svalue = parseInt(snumber.value, 2);
143+
if (snot.hasAttribute('checked')) {
144+
svalue = ~svalue;
145+
}
146+
147+
let operation = event.target.getAttribute('operation');
148+
149+
switch (operation) {
150+
case 'and':
151+
res = fvalue & svalue;
152+
break;
153+
case 'or':
154+
res = fvalue | svalue;
155+
break;
156+
default:
157+
throw new Error('Unknown Operation');
158+
}
159+
160+
result.innerHTML = res.toString(2);
161+
});
162+
});
163+
};
164+
165+
setTimeout('main()');
166+
</script>
167+
</head>
168+
169+
170+
<body>
171+
<div id="form">
172+
<div id="first">
173+
<label id="fnot" class="clickable check">NOT</label>
174+
<input type="text" id="fnumber" class="binary-input" />
175+
</div>
176+
<div id="second">
177+
<label id="snot" class="clickable check">NOT</label>
178+
<input type="text" id="snumber" class="binary-input" />
179+
</div>
180+
181+
<div>
182+
<label id="and" class="clickable button" operation="and">AND</label>
183+
<label id="or" class="clickable button" operation="or">OR</label>
184+
</div>
185+
</div>
186+
<div id="result-area">
187+
<span id="result">N/A</span>
188+
</div>
189+
<label id="close" class="clickable button">Close</label>
190+
</body>
191+
</html>

tests/atest/linux_tests.robot

-18
This file was deleted.

0 commit comments

Comments
 (0)