Browse Source

Update tests for new module helpers.

pull/379/head
Ron DuPlain 13 years ago
parent
commit
fde6e364a4
  1. 109
      flask/testsuite/config.py
  2. 3
      flask/testsuite/test_apps/lib/python2.5/site-packages/site_app.py
  3. 3
      flask/testsuite/test_apps/lib/python2.5/site-packages/site_package/__init__.py
  4. 4
      flask/testsuite/test_apps/main_app.py
  5. 3
      flask/testsuite/test_apps/path/installed_package/__init__.py

109
flask/testsuite/config.py

@ -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)
def test_prefix_installed_paths(self): if 'installed_package' in sys.modules:
import types del sys.modules['installed_package']
expected_prefix = os.path.abspath(sys.prefix)
package_path = os.path.join(expected_prefix, 'lib', 'python2.5', def test_prefix_package_paths(self):
'site-packages', 'myapp') here = os.path.abspath(os.path.dirname(__file__))
mod = types.ModuleType('myapp') expected_prefix = os.path.join(here, 'test_apps')
mod.__path__ = [package_path] real_prefix, sys.prefix = sys.prefix, expected_prefix
mod.__file__ = os.path.join(package_path, '__init__.py') site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')
sys.modules['myapp'] = mod sys.path.append(site_packages)
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():

3
flask/testsuite/test_apps/lib/python2.5/site-packages/site_app.py

@ -0,0 +1,3 @@
import flask
app = flask.Flask(__name__)

3
flask/testsuite/test_apps/lib/python2.5/site-packages/site_package/__init__.py

@ -0,0 +1,3 @@
import flask
app = flask.Flask(__name__)

4
flask/testsuite/test_apps/main_app.py

@ -0,0 +1,4 @@
import flask
# Test Flask initialization with main module.
app = flask.Flask('__main__')

3
flask/testsuite/test_apps/path/installed_package/__init__.py

@ -0,0 +1,3 @@
import flask
app = flask.Flask(__name__)
Loading…
Cancel
Save