Skip to content

Commit f4bfae6

Browse files
committed
Added flaskext tester
1 parent 66c1395 commit f4bfae6

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/flaskext_test.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Flask Extension Tests
4+
~~~~~~~~~~~~~~~~~~~~~
5+
6+
Tests the Flask extensions.
7+
8+
:copyright: (c) 2010 by Ali Afshar.
9+
:license: BSD, see LICENSE for more details.
10+
"""
11+
12+
from __future__ import with_statement
13+
14+
import tempfile, subprocess, urllib2, os
15+
16+
from flask import json
17+
18+
from setuptools.package_index import PackageIndex
19+
from setuptools.archive_util import unpack_archive
20+
21+
flask_svc_url = 'http://flask.pocoo.org/extensions/'
22+
tdir = tempfile.mkdtemp()
23+
24+
25+
def run_tests(checkout_dir):
26+
cmd = ['tox']
27+
return subprocess.call(cmd, cwd=checkout_dir,
28+
stdout=open(os.path.join(tdir, 'tox.log'), 'w'),
29+
stderr=subprocess.STDOUT)
30+
31+
32+
def get_test_command(checkout_dir):
33+
files = set(os.listdir(checkout_dir))
34+
if 'Makefile' in files:
35+
return 'make test'
36+
elif 'conftest.py' in files:
37+
return 'py.test'
38+
else:
39+
return 'nosetests'
40+
41+
42+
def fetch_extensions_list():
43+
req = urllib2.Request(flask_svc_url, headers={'accept':'application/json'})
44+
d = urllib2.urlopen(req).read()
45+
data = json.loads(d)
46+
for ext in data['extensions']:
47+
yield ext
48+
49+
50+
def checkout_extension(ext):
51+
name = ext['name']
52+
root = os.path.join(tdir, name)
53+
os.mkdir(root)
54+
checkout_path = PackageIndex().download(ext['name'], root)
55+
unpack_archive(checkout_path, root)
56+
path = None
57+
for fn in os.listdir(root):
58+
path = os.path.join(root, fn)
59+
if os.path.isdir(path):
60+
break
61+
return path
62+
63+
64+
tox_template = """[tox]
65+
envlist=py26
66+
67+
[testenv]
68+
commands=
69+
%s
70+
downloadcache=
71+
%s
72+
"""
73+
74+
def create_tox_ini(checkout_path):
75+
tox_path = os.path.join(checkout_path, 'tox.ini')
76+
if not os.path.exists(tox_path):
77+
with open(tox_path, 'w') as f:
78+
f.write(tox_template % (get_test_command(checkout_path), tdir))
79+
80+
# XXX command line
81+
only_approved = True
82+
83+
def test_all_extensions(only_approved=only_approved):
84+
for ext in fetch_extensions_list():
85+
if ext['approved'] or not only_approved:
86+
checkout_path = checkout_extension(ext)
87+
create_tox_ini(checkout_path)
88+
ret = run_tests(checkout_path)
89+
yield ext['name'], ret
90+
91+
def main():
92+
for name, ret in test_all_extensions():
93+
print name, ret
94+
95+
96+
if __name__ == '__main__':
97+
main()

0 commit comments

Comments
 (0)