forked from rodrigomanhaes/should-splinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all_examples.py
executable file
·49 lines (38 loc) · 1.37 KB
/
run_all_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import doctest
import unittest
import os
import sys
import glob
from should_dsl import should, should_not
from splinter.browser import Browser
from tests.fake_webapp import start_server, stop_server, EXAMPLE_APP
browser = Browser()
def test_suite():
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
if sys.version_info >= (3,):
flags |= doctest.IGNORE_EXCEPTION_DETAIL
doctests_path = os.path.join('tests')
suite = unittest.TestSuite()
globs = {'browser': browser, 'should': should, 'should_not': should_not}
suite.addTest(doctest.DocFileSuite('README.rst', optionflags=flags,
globs=globs))
for doctest_file in os.listdir(doctests_path):
if doctest_file.endswith('.txt'):
suite.addTest(doctest.DocFileSuite(os.path.join(doctests_path,
doctest_file),
globs=globs,
optionflags=flags))
return suite
def setup():
start_server()
browser.visit(EXAMPLE_APP)
def teardown():
browser.quit()
stop_server()
if __name__ == '__main__':
runner = unittest.TextTestRunner(verbosity=2)
setup()
result = runner.run(test_suite())
teardown()
sys.exit(int(bool(result.failures or result.errors)))