This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
forked from aldryn/aldryn-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_build.py
73 lines (59 loc) · 1.64 KB
/
test_build.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import os
import socket
import sys
from shutil import rmtree as _rmtree
from tempfile import mkdtemp, _exists
import aldryn_events
from sphinx.application import Sphinx
try:
import enchant
except ImportError:
enchant = None
ROOT_DIR = os.path.dirname(aldryn_events.__file__)
DOCS_DIR = os.path.abspath(os.path.join(ROOT_DIR, u'..', u'docs'))
def has_no_internet():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(5)
s.connect(('4.4.4.2', 80))
s.send(b"hello")
except socket.error: # no internet
return True
return False
def test_build(builder_name='html', warnings=False):
"""
Try to build docs, by default sphinx is writing its messages to std.out
and errors to std.err.
To test with different builders change builder_name, default is 'html'
"""
OUT_DIR = mkdtemp()
app = Sphinx(
srcdir=DOCS_DIR,
confdir=DOCS_DIR,
outdir=OUT_DIR,
doctreedir=OUT_DIR,
buildername=builder_name,
warningiserror=warnings,
)
app.build()
# cleanup
cleanup(OUT_DIR)
return app.statuscode
def cleanup(dirname):
"""
Delete temp directory for so that no overlap with other builds.
"""
if _exists(dirname):
_rmtree(dirname)
if __name__ == '__main__':
args = {}
if has_no_internet():
print('Seems there is no internet, cannot test without internet...')
sys.exit(1)
try:
args['builder_name'] = sys.argv[1]
except IndexError:
pass
sys.exit(test_build(**args))