Skip to content

Commit 03a5c63

Browse files
authored
Approvaltests (#1173)
Adds ApprovalTests support the project.
1 parent 7ccc021 commit 03a5c63

File tree

8 files changed

+73
-3
lines changed

8 files changed

+73
-3
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ before_script:
7474
- echo $INTERPRETER
7575
- $INTERPRETER --version
7676
- $INTERPRETER -m pip install .
77-
- $INTERPRETER -m pip install -r requirements-dev.txt
77+
- if [ "$JYTHON" == "true" ]; then
78+
$INTERPRETER -m pip install mockito;
79+
$INTERPRETER -m pip install robotstatuschecker;
80+
$INTERPRETER -m pip install -r requirements.txt;
81+
else
82+
$INTERPRETER -m pip install -r requirements-dev.txt;
83+
fi
7884
- $INTERPRETER -m pip install selenium==$SELENIUM
7985
- $INTERPRETER -m pip install robotframework==$ROBOTFRAMEWORK
8086
script:

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
mockito >= 1.0.0
55
robotstatuschecker
6+
approvaltests >= 0.2.3
67

78
# Include normal dependencies from requirements.txt. Makes it possible to use
89
# requirements-dev.txt as a single requirement file in PyCharm and other IDEs.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
3+
# Can be removed when Robot Framework 2.8.4 is not supported.
4+
JYTHON = sys.platform.startswith('java')

utest/README.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,25 @@ Unit test can be executed by running::
1515

1616
The utest directory contains everything needed to run SeleniumLibrary unit tests.
1717
This includes:
18-
- Unit test in `test` folder.
19-
- Unit test runner: `run.py`
18+
19+
- Unit test in `test` folder.
20+
- Unit test runner: `run.py`
2021

2122
Unit test are executed using the interpreter which starts the `run.py` script.
2223

24+
ApprovalTests
25+
-------------
26+
For unit test, it is possible to use `ApprovalTests`_ framework. ApprovalTests
27+
provides an easy and visual way to compare strings in unit tests. For more
28+
details, please read `ApprovalTests`_ documentation and `ApprovalTests blog post`_.
29+
The downside of ApprovalTests is that it does not work when using `Jython`_
30+
as an interpreter. Therefore all unit tests using ApprovalTests imports
31+
must handled with `try/except ImportError:` and skipped with:
32+
`@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')`. The `JYTHON` is
33+
imported from `from robot.utils import JYTHON`
34+
35+
2336
.. _unittest: https://docs.python.org/3/library/unittest.html
37+
.. _ApprovalTests: https://github.com/approvals/ApprovalTests.Python
38+
.. _ApprovalTests blog post: http://blog.approvaltests.com/
39+
.. _Jython: http://www.jython.org/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
[
3+
"Diffuse",
4+
"/usr/bin/diffuse"
5+
]
6+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"subdirectory": "approved_files"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
code here
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import unittest
3+
4+
from SeleniumLibrary.utils.platform import JYTHON
5+
try:
6+
from approvaltests.approvals import verify
7+
from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory
8+
except ImportError:
9+
if JYTHON:
10+
verify = None
11+
GenericDiffReporterFactory = None
12+
else:
13+
raise
14+
15+
from SeleniumLibrary.keywords import JavaScriptKeywords
16+
17+
18+
class JavaScriptKeywordsTest(unittest.TestCase):
19+
20+
@classmethod
21+
@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')
22+
def setUpClass(cls):
23+
cls.javascript = JavaScriptKeywords(None)
24+
path = os.path.dirname(__file__)
25+
reporter_json = os.path.abspath(os.path.join(path, '..', 'approvals_reporters.json'))
26+
factory = GenericDiffReporterFactory()
27+
factory.load(reporter_json)
28+
cls.reporter = factory.get_first_working()
29+
30+
@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')
31+
def test_get_javascript(self):
32+
code = self.javascript._get_javascript_to_execute('code here')
33+
verify(code, self.reporter)

0 commit comments

Comments
 (0)