Browse Source

Rename fixture apps_tmpdir

pull/1165/head
Markus Unterwaditzer 11 years ago
parent
commit
77d887526d
  1. 24
      tests/conftest.py
  2. 48
      tests/test_config.py
  3. 20
      tests/test_ext.py
  4. 4
      tests/test_helpers.py

24
tests/conftest.py

@ -66,23 +66,23 @@ def limit_loader(request, monkeypatch):
@pytest.fixture @pytest.fixture
def apps_tmpdir(tmpdir, monkeypatch): def modules_tmpdir(tmpdir, monkeypatch):
'''Test folder for all instance tests.''' '''A tmpdir added to sys.path'''
rv = tmpdir.mkdir('test_apps') rv = tmpdir.mkdir('modules_tmpdir')
monkeypatch.syspath_prepend(str(rv)) monkeypatch.syspath_prepend(str(rv))
return rv return rv
@pytest.fixture @pytest.fixture
def apps_tmpdir_prefix(apps_tmpdir, monkeypatch): def modules_tmpdir_prefix(modules_tmpdir, monkeypatch):
monkeypatch.setattr(sys, 'prefix', str(apps_tmpdir)) monkeypatch.setattr(sys, 'prefix', str(modules_tmpdir))
return apps_tmpdir return modules_tmpdir
@pytest.fixture @pytest.fixture
def site_packages(apps_tmpdir, monkeypatch): def site_packages(modules_tmpdir, monkeypatch):
'''Create a fake site-packages''' '''Create a fake site-packages'''
rv = apps_tmpdir \ rv = modules_tmpdir \
.mkdir('lib')\ .mkdir('lib')\
.mkdir('python{x[0]}.{x[1]}'.format(x=sys.version_info))\ .mkdir('python{x[0]}.{x[1]}'.format(x=sys.version_info))\
.mkdir('site-packages') .mkdir('site-packages')
@ -91,10 +91,10 @@ def site_packages(apps_tmpdir, monkeypatch):
@pytest.fixture @pytest.fixture
def install_egg(apps_tmpdir, monkeypatch): def install_egg(modules_tmpdir, monkeypatch):
'''Generate egg from package name inside base and put the egg into '''Generate egg from package name inside base and put the egg into
sys.path''' sys.path'''
def inner(name, base=apps_tmpdir): def inner(name, base=modules_tmpdir):
if not isinstance(name, str): if not isinstance(name, str):
raise ValueError(name) raise ValueError(name)
base.join(name).ensure_dir() base.join(name).ensure_dir()
@ -112,9 +112,9 @@ def install_egg(apps_tmpdir, monkeypatch):
import subprocess import subprocess
subprocess.check_call( subprocess.check_call(
[sys.executable, 'setup.py', 'bdist_egg'], [sys.executable, 'setup.py', 'bdist_egg'],
cwd=str(apps_tmpdir) cwd=str(modules_tmpdir)
) )
egg_path, = apps_tmpdir.join('dist/').listdir() egg_path, = modules_tmpdir.join('dist/').listdir()
monkeypatch.syspath_prepend(str(egg_path)) monkeypatch.syspath_prepend(str(egg_path))
return egg_path return egg_path
return inner return inner

48
tests/test_config.py

@ -182,16 +182,16 @@ class TestConfig(object):
class TestInstance(object): class TestInstance(object):
def test_explicit_instance_paths(self, apps_tmpdir): def test_explicit_instance_paths(self, modules_tmpdir):
with pytest.raises(ValueError) as excinfo: with pytest.raises(ValueError) as excinfo:
flask.Flask(__name__, instance_path='instance') flask.Flask(__name__, instance_path='instance')
assert 'must be absolute' in str(excinfo.value) assert 'must be absolute' in str(excinfo.value)
app = flask.Flask(__name__, instance_path=str(apps_tmpdir)) app = flask.Flask(__name__, instance_path=str(modules_tmpdir))
assert app.instance_path == str(apps_tmpdir) assert app.instance_path == str(modules_tmpdir)
def test_main_module_paths(self, apps_tmpdir, purge_module): def test_main_module_paths(self, modules_tmpdir, purge_module):
app = apps_tmpdir.join('main_app.py') app = modules_tmpdir.join('main_app.py')
app.write('import flask\n\napp = flask.Flask("__main__")') app.write('import flask\n\napp = flask.Flask("__main__")')
purge_module('main_app') purge_module('main_app')
@ -199,8 +199,8 @@ class TestInstance(object):
here = os.path.abspath(os.getcwd()) here = os.path.abspath(os.getcwd())
assert app.instance_path == os.path.join(here, 'instance') assert app.instance_path == os.path.join(here, 'instance')
def test_uninstalled_module_paths(self, apps_tmpdir, purge_module): def test_uninstalled_module_paths(self, modules_tmpdir, purge_module):
app = apps_tmpdir.join('config_module_app.py').write( app = modules_tmpdir.join('config_module_app.py').write(
'import os\n' 'import os\n'
'import flask\n' 'import flask\n'
'here = os.path.abspath(os.path.dirname(__file__))\n' 'here = os.path.abspath(os.path.dirname(__file__))\n'
@ -209,10 +209,10 @@ class TestInstance(object):
purge_module('config_module_app') purge_module('config_module_app')
from config_module_app import app from config_module_app import app
assert app.instance_path == str(apps_tmpdir.join('instance')) assert app.instance_path == str(modules_tmpdir.join('instance'))
def test_uninstalled_package_paths(self, apps_tmpdir, purge_module): def test_uninstalled_package_paths(self, modules_tmpdir, purge_module):
app = apps_tmpdir.mkdir('config_package_app') app = modules_tmpdir.mkdir('config_package_app')
init = app.join('__init__.py') init = app.join('__init__.py')
init.write( init.write(
'import os\n' 'import os\n'
@ -223,9 +223,9 @@ class TestInstance(object):
purge_module('config_package_app') purge_module('config_package_app')
from config_package_app import app from config_package_app import app
assert app.instance_path == str(apps_tmpdir.join('instance')) assert app.instance_path == str(modules_tmpdir.join('instance'))
def test_installed_module_paths(self, apps_tmpdir, apps_tmpdir_prefix, def test_installed_module_paths(self, modules_tmpdir, modules_tmpdir_prefix,
purge_module, site_packages, limit_loader): purge_module, site_packages, limit_loader):
site_packages.join('site_app.py').write( site_packages.join('site_app.py').write(
'import flask\n' 'import flask\n'
@ -235,12 +235,12 @@ class TestInstance(object):
from site_app import app from site_app import app
assert app.instance_path == \ assert app.instance_path == \
apps_tmpdir.join('var').join('site_app-instance') modules_tmpdir.join('var').join('site_app-instance')
def test_installed_package_paths(self, limit_loader, apps_tmpdir, def test_installed_package_paths(self, limit_loader, modules_tmpdir,
apps_tmpdir_prefix, purge_module, modules_tmpdir_prefix, purge_module,
monkeypatch): monkeypatch):
installed_path = apps_tmpdir.mkdir('path') installed_path = modules_tmpdir.mkdir('path')
monkeypatch.syspath_prepend(installed_path) monkeypatch.syspath_prepend(installed_path)
app = installed_path.mkdir('installed_package') app = installed_path.mkdir('installed_package')
@ -250,10 +250,10 @@ class TestInstance(object):
from installed_package import app from installed_package import app
assert app.instance_path == \ assert app.instance_path == \
apps_tmpdir.join('var').join('installed_package-instance') modules_tmpdir.join('var').join('installed_package-instance')
def test_prefix_package_paths(self, limit_loader, apps_tmpdir, def test_prefix_package_paths(self, limit_loader, modules_tmpdir,
apps_tmpdir_prefix, purge_module, modules_tmpdir_prefix, purge_module,
site_packages): site_packages):
app = site_packages.mkdir('site_package') app = site_packages.mkdir('site_package')
init = app.join('__init__.py') init = app.join('__init__.py')
@ -262,18 +262,18 @@ class TestInstance(object):
import site_package import site_package
assert site_package.app.instance_path == \ assert site_package.app.instance_path == \
apps_tmpdir.join('var').join('site_package-instance') modules_tmpdir.join('var').join('site_package-instance')
def test_egg_installed_paths(self, install_egg, apps_tmpdir, def test_egg_installed_paths(self, install_egg, modules_tmpdir,
apps_tmpdir_prefix): modules_tmpdir_prefix):
apps_tmpdir.mkdir('site_egg').join('__init__.py').write( modules_tmpdir.mkdir('site_egg').join('__init__.py').write(
'import flask\n\napp = flask.Flask(__name__)' 'import flask\n\napp = flask.Flask(__name__)'
) )
install_egg('site_egg') install_egg('site_egg')
try: try:
import site_egg import site_egg
assert site_egg.app.instance_path == \ assert site_egg.app.instance_path == \
str(apps_tmpdir.join('var/').join('site_egg-instance')) str(modules_tmpdir.join('var/').join('site_egg-instance'))
finally: finally:
if 'site_egg' in sys.modules: if 'site_egg' in sys.modules:
del sys.modules['site_egg'] del sys.modules['site_egg']

20
tests/test_ext.py

@ -55,28 +55,28 @@ def importhook_setup(monkeypatch, request):
@pytest.fixture @pytest.fixture
def newext_simple(apps_tmpdir): def newext_simple(modules_tmpdir):
x = apps_tmpdir.join('flask_newext_simple.py') x = modules_tmpdir.join('flask_newext_simple.py')
x.write('ext_id = "newext_simple"') x.write('ext_id = "newext_simple"')
@pytest.fixture @pytest.fixture
def oldext_simple(apps_tmpdir): def oldext_simple(modules_tmpdir):
flaskext = apps_tmpdir.mkdir('flaskext') flaskext = modules_tmpdir.mkdir('flaskext')
flaskext.join('__init__.py').write('\n') flaskext.join('__init__.py').write('\n')
flaskext.join('oldext_simple.py').write('ext_id = "oldext_simple"') flaskext.join('oldext_simple.py').write('ext_id = "oldext_simple"')
@pytest.fixture @pytest.fixture
def newext_package(apps_tmpdir): def newext_package(modules_tmpdir):
pkg = apps_tmpdir.mkdir('flask_newext_package') pkg = modules_tmpdir.mkdir('flask_newext_package')
pkg.join('__init__.py').write('ext_id = "newext_package"') pkg.join('__init__.py').write('ext_id = "newext_package"')
pkg.join('submodule.py').write('def test_function():\n return 42\n') pkg.join('submodule.py').write('def test_function():\n return 42\n')
@pytest.fixture @pytest.fixture
def oldext_package(apps_tmpdir): def oldext_package(modules_tmpdir):
flaskext = apps_tmpdir.mkdir('flaskext') flaskext = modules_tmpdir.mkdir('flaskext')
flaskext.join('__init__.py').write('\n') flaskext.join('__init__.py').write('\n')
oldext = flaskext.mkdir('oldext_package') oldext = flaskext.mkdir('oldext_package')
oldext.join('__init__.py').write('ext_id = "oldext_package"') oldext.join('__init__.py').write('ext_id = "oldext_package"')
@ -85,8 +85,8 @@ def oldext_package(apps_tmpdir):
@pytest.fixture @pytest.fixture
def flaskext_broken(apps_tmpdir): def flaskext_broken(modules_tmpdir):
ext = apps_tmpdir.mkdir('flask_broken') ext = modules_tmpdir.mkdir('flask_broken')
ext.join('b.py').write('\n') ext.join('b.py').write('\n')
ext.join('__init__.py').write('import flask.ext.broken.b\n' ext.join('__init__.py').write('import flask.ext.broken.b\n'
'import missing_module') 'import missing_module')

4
tests/test_helpers.py

@ -577,8 +577,8 @@ class TestNoImports(object):
imp modules in the Python standard library. imp modules in the Python standard library.
""" """
def test_name_with_import_error(self, apps_tmpdir): def test_name_with_import_error(self, modules_tmpdir):
apps_tmpdir.join('importerror.py').write('raise NotImplementedError()') modules_tmpdir.join('importerror.py').write('raise NotImplementedError()')
try: try:
flask.Flask('importerror') flask.Flask('importerror')
except NotImplementedError: except NotImplementedError:

Loading…
Cancel
Save