-
Notifications
You must be signed in to change notification settings - Fork 20
/
run_tests.py
118 lines (90 loc) · 2.91 KB
/
run_tests.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import sys
import urllib2
import subprocess
import zipfile
import cStringIO
import json
import nginc
BIN = os.path.expanduser('~/.local/bin')
FLOW = os.path.join(BIN, 'flow')
BROWSERSTACK = os.path.join(BIN, 'BrowserStackLocal')
class AppData(object):
min_version = None
def install(self):
# check if already installed
if os.path.exists(self.executable):
if not self.min_version or self.get_version() >= self.min_version:
return True
# download flow
response = urllib2.urlopen(self.download_url)
zip_data = cStringIO.StringIO(response.read())
zip_file = zipfile.ZipFile(zip_data)
exe = zip_file.open(self.zip_path).read()
with open(self.executable, 'w') as out:
out.write(exe)
os.chmod(self.executable, 0744)
def call(self, *args):
cmd = [self.executable]
cmd.extend(args)
return subprocess.call(cmd)
class Flow(AppData):
download_url = 'https://github.com/facebook/flow/releases/download/v0.52.0/flow-linux64-v0.52.0.zip'
zip_path = 'flow/flow'
min_version = [0, 14, 0]
executable = FLOW
def get_version(self):
version = subprocess.check_output([self.executable, 'version'])
version = version.strip()
i = version.rfind(' ')
version = version[i:]
return map(int, version.split('.'))
class BrowserStackLocal(AppData):
download_url = 'https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip'
zip_path = 'BrowserStackLocal'
min_version = [3, 7]
executable = BROWSERSTACK
def get_version(self):
version = subprocess.check_output([BROWSERSTACK, '-version']).strip()
i = version.rfind(' ')
version = version[i:].strip('v')
return map(int, version.split('.'))
def __init__(self):
# read config
self.proc = None
config = os.path.expanduser('~/.browserstack.json')
self.config = json.load(open(config))
print self.config
def start(self, arg):
if self.proc:
self.stop()
cmd = [self.executable, self.config['key'], arg]
self.proc = subprocess.Popen(cmd)
def stop(self):
self.proc.terminate()
self.proc = None
def main():
if not os.path.exists(BIN):
os.makedirs(BIN)
flow = Flow()
flow.install()
# TODO use flow
# assert flow.call() == 0
# start nginx
nginx = nginc.start('.', port=8000)
# forward port to browserstack
browserstack = BrowserStackLocal()
browserstack.install()
browserstack.start('localhost,8000,0')
# wait for things to settle
import time
time.sleep(5)
# run browserstack tests
ok = subprocess.call(['python', 'test/browserstack.py'])
nginx.terminate()
browserstack.stop()
sys.exit(ok)
# browserstack
# have fun here
if __name__ == '__main__':
main()