forked from orbit-oss/flask
Update tests for new module helpers.
This commit is contained in:
parent
a3b30b7e3b
commit
fde6e364a4
5 changed files with 77 additions and 51 deletions
|
|
@ -98,6 +98,14 @@ class InstanceTestCase(FlaskTestCase):
|
||||||
app = flask.Flask(__name__, instance_path=here)
|
app = flask.Flask(__name__, instance_path=here)
|
||||||
self.assert_equal(app.instance_path, here)
|
self.assert_equal(app.instance_path, here)
|
||||||
|
|
||||||
|
def test_main_module_paths(self):
|
||||||
|
# Test an app with '__main__' as the import name, uses cwd.
|
||||||
|
from main_app import app
|
||||||
|
here = os.path.abspath(os.getcwd())
|
||||||
|
self.assert_equal(app.instance_path, os.path.join(here, 'instance'))
|
||||||
|
if 'main_app' in sys.modules:
|
||||||
|
del sys.modules['main_app']
|
||||||
|
|
||||||
def test_uninstalled_module_paths(self):
|
def test_uninstalled_module_paths(self):
|
||||||
from config_module_app import app
|
from config_module_app import app
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
@ -109,70 +117,75 @@ class InstanceTestCase(FlaskTestCase):
|
||||||
self.assert_equal(app.instance_path, os.path.join(here, 'test_apps', 'instance'))
|
self.assert_equal(app.instance_path, os.path.join(here, 'test_apps', 'instance'))
|
||||||
|
|
||||||
def test_installed_module_paths(self):
|
def test_installed_module_paths(self):
|
||||||
import types
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
expected_prefix = os.path.abspath('foo')
|
expected_prefix = os.path.join(here, 'test_apps')
|
||||||
mod = types.ModuleType('myapp')
|
real_prefix, sys.prefix = sys.prefix, expected_prefix
|
||||||
mod.__file__ = os.path.join(expected_prefix, 'lib', 'python2.5',
|
site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')
|
||||||
'site-packages', 'myapp.py')
|
sys.path.append(site_packages)
|
||||||
sys.modules['myapp'] = mod
|
|
||||||
try:
|
try:
|
||||||
mod.app = flask.Flask(mod.__name__)
|
import site_app
|
||||||
self.assert_equal(mod.app.instance_path,
|
self.assert_equal(site_app.app.instance_path,
|
||||||
os.path.join(expected_prefix, 'var',
|
os.path.join(expected_prefix, 'var',
|
||||||
'myapp-instance'))
|
'site_app-instance'))
|
||||||
finally:
|
finally:
|
||||||
sys.modules['myapp'] = None
|
sys.prefix = real_prefix
|
||||||
|
sys.path.remove(site_packages)
|
||||||
|
if 'site_app' in sys.modules:
|
||||||
|
del sys.modules['site_app']
|
||||||
|
|
||||||
def test_installed_package_paths(self):
|
def test_installed_package_paths(self):
|
||||||
import types
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
expected_prefix = os.path.abspath('foo')
|
expected_prefix = os.path.join(here, 'test_apps')
|
||||||
package_path = os.path.join(expected_prefix, 'lib', 'python2.5',
|
real_prefix, sys.prefix = sys.prefix, expected_prefix
|
||||||
'site-packages', 'myapp')
|
installed_path = os.path.join(expected_prefix, 'path')
|
||||||
mod = types.ModuleType('myapp')
|
sys.path.append(installed_path)
|
||||||
mod.__path__ = [package_path]
|
|
||||||
mod.__file__ = os.path.join(package_path, '__init__.py')
|
|
||||||
sys.modules['myapp'] = mod
|
|
||||||
try:
|
try:
|
||||||
mod.app = flask.Flask(mod.__name__)
|
import installed_package
|
||||||
self.assert_equal(mod.app.instance_path,
|
self.assert_equal(installed_package.app.instance_path,
|
||||||
os.path.join(expected_prefix, 'var',
|
os.path.join(expected_prefix, 'var',
|
||||||
'myapp-instance'))
|
'installed_package-instance'))
|
||||||
finally:
|
finally:
|
||||||
sys.modules['myapp'] = None
|
sys.prefix = real_prefix
|
||||||
|
sys.path.remove(installed_path)
|
||||||
|
if 'installed_package' in sys.modules:
|
||||||
|
del sys.modules['installed_package']
|
||||||
|
|
||||||
def test_prefix_installed_paths(self):
|
def test_prefix_package_paths(self):
|
||||||
import types
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
expected_prefix = os.path.abspath(sys.prefix)
|
expected_prefix = os.path.join(here, 'test_apps')
|
||||||
package_path = os.path.join(expected_prefix, 'lib', 'python2.5',
|
real_prefix, sys.prefix = sys.prefix, expected_prefix
|
||||||
'site-packages', 'myapp')
|
site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')
|
||||||
mod = types.ModuleType('myapp')
|
sys.path.append(site_packages)
|
||||||
mod.__path__ = [package_path]
|
|
||||||
mod.__file__ = os.path.join(package_path, '__init__.py')
|
|
||||||
sys.modules['myapp'] = mod
|
|
||||||
try:
|
try:
|
||||||
mod.app = flask.Flask(mod.__name__)
|
import site_package
|
||||||
self.assert_equal(mod.app.instance_path,
|
self.assert_equal(site_package.app.instance_path,
|
||||||
os.path.join(expected_prefix, 'var',
|
os.path.join(expected_prefix, 'var',
|
||||||
'myapp-instance'))
|
'site_package-instance'))
|
||||||
finally:
|
finally:
|
||||||
sys.modules['myapp'] = None
|
sys.prefix = real_prefix
|
||||||
|
sys.path.remove(site_packages)
|
||||||
|
if 'site_package' in sys.modules:
|
||||||
|
del sys.modules['site_package']
|
||||||
|
|
||||||
def test_egg_installed_paths(self):
|
def test_egg_installed_paths(self):
|
||||||
import types
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
expected_prefix = os.path.abspath(sys.prefix)
|
expected_prefix = os.path.join(here, 'test_apps')
|
||||||
package_path = os.path.join(expected_prefix, 'lib', 'python2.5',
|
real_prefix, sys.prefix = sys.prefix, expected_prefix
|
||||||
'site-packages', 'MyApp.egg', 'myapp')
|
site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')
|
||||||
mod = types.ModuleType('myapp')
|
egg_path = os.path.join(site_packages, 'SiteEgg.egg')
|
||||||
mod.__path__ = [package_path]
|
sys.path.append(site_packages)
|
||||||
mod.__file__ = os.path.join(package_path, '__init__.py')
|
sys.path.append(egg_path)
|
||||||
sys.modules['myapp'] = mod
|
|
||||||
try:
|
try:
|
||||||
mod.app = flask.Flask(mod.__name__)
|
import site_egg # in SiteEgg.egg
|
||||||
self.assert_equal(mod.app.instance_path,
|
self.assert_equal(site_egg.app.instance_path,
|
||||||
os.path.join(expected_prefix, 'var',
|
os.path.join(expected_prefix, 'var',
|
||||||
'myapp-instance'))
|
'site_egg-instance'))
|
||||||
finally:
|
finally:
|
||||||
sys.modules['myapp'] = None
|
sys.prefix = real_prefix
|
||||||
|
sys.path.remove(site_packages)
|
||||||
|
sys.path.remove(egg_path)
|
||||||
|
if 'site_egg' in sys.modules:
|
||||||
|
del sys.modules['site_egg']
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
import flask
|
||||||
|
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
import flask
|
||||||
|
|
||||||
|
app = flask.Flask(__name__)
|
||||||
4
flask/testsuite/test_apps/main_app.py
Normal file
4
flask/testsuite/test_apps/main_app.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import flask
|
||||||
|
|
||||||
|
# Test Flask initialization with main module.
|
||||||
|
app = flask.Flask('__main__')
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
import flask
|
||||||
|
|
||||||
|
app = flask.Flask(__name__)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue