Skip to content
Myr

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

1 file+97 added−0 removed

added:tests/flaskext_test.py+97 added
1# -*- coding: utf-8 -*-2"""3 Flask Extension Tests4 ~~~~~~~~~~~~~~~~~~~~~56 Tests the Flask extensions.78 :copyright: (c) 2010 by Ali Afshar.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1314import tempfile, subprocess, urllib2, os1516from flask import json1718from setuptools.package_index import PackageIndex19from setuptools.archive_util import unpack_archive2021flask_svc_url = 'http://flask.pocoo.org/extensions/'22tdir = tempfile.mkdtemp()232425def 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)303132def 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'404142def 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 ext484950def 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 path626364tox_template = """[tox]65envlist=py266667[testenv]68commands=69%s70downloadcache=71%s72"""7374def 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))7980# XXX command line81only_approved = True8283def 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'], ret9091def main():92 for name, ret in test_all_extensions():93 print name, ret949596if __name__ == '__main__':97 main()