Added flaskext tester
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 66c1395 · Browse files · 1 file·+97 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+97 added−0 removed
- tests:+97 added−0 removed
Provenance
- Commit
f4bfae6- Tree
9156312- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
66c1395
1 file changed+97 added−0 removed
added:tests/flaskext_test.py+97 added
1+# -*- coding: utf-8 -*-2+"""3+ Flask Extension Tests4+ ~~~~~~~~~~~~~~~~~~~~~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_statement13+14+import tempfile, subprocess, urllib2, os15+16+from flask import json17+18+from setuptools.package_index import PackageIndex19+from setuptools.archive_util import unpack_archive20+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 ext48+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 = None57+ for fn in os.listdir(root):58+ path = os.path.join(root, fn)59+ if os.path.isdir(path):60+ break61+ return path62+63+64+tox_template = """[tox]65+envlist=py2666+67+[testenv]68+commands=69+%s70+downloadcache=71+%s72+"""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 line81+only_approved = True82+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'], ret90+91+def main():92+ for name, ret in test_all_extensions():93+ print name, ret94+95+96+if __name__ == '__main__':97+ main()