Update tests for new module helpers.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ron DuPlain · committed by Ron DuPlain · parent a3b30b7 · Browse files · 5 files·+77 added−51 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+77 added−51 removed
- other:+77 added−51 removed
Provenance
- Commit
fde6e36- Tree
7c4dae8- Author
Ron DuPlain <ron.duplain@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent
a3b30b7
5 files changed+77 added−51 removed
added:flask/testsuite/test_apps/lib/python2.5/site-packages/site_package/__init__.py+3 added
1+import flask2+3+app = flask.Flask(__name__)added:flask/testsuite/test_apps/lib/python2.5/site-packages/site_app.py+3 added
1+import flask2+3+app = flask.Flask(__name__)added:flask/testsuite/test_apps/path/installed_package/__init__.py+3 added
1+import flask2+3+app = flask.Flask(__name__)added:flask/testsuite/test_apps/main_app.py+4 added
1+import flask2+3+# Test Flask initialization with main module.4+app = flask.Flask('__main__')modified:flask/testsuite/config.py+64 added-51 removed
96 unmodified lines97 98 app = flask.Flask(__name__, instance_path=here)99 self.assert_equal(app.instance_path, here)100 101+ def test_main_module_paths(self):102+ # Test an app with '__main__' as the import name, uses cwd.103+ from main_app import app104+ here = os.path.abspath(os.getcwd())105+ self.assert_equal(app.instance_path, os.path.join(here, 'instance'))106+ if 'main_app' in sys.modules:107+ del sys.modules['main_app']108+109 def test_uninstalled_module_paths(self):110 from config_module_app import app111 here = os.path.abspath(os.path.dirname(__file__))112 self.assert_equal(app.instance_path, os.path.join(here, 'test_apps', 'instance'))3 unmodified lines116 here = os.path.abspath(os.path.dirname(__file__))117 self.assert_equal(app.instance_path, os.path.join(here, 'test_apps', 'instance'))118 119 def test_installed_module_paths(self):112- import types113- expected_prefix = os.path.abspath('foo')114- mod = types.ModuleType('myapp')115- mod.__file__ = os.path.join(expected_prefix, 'lib', 'python2.5',116- 'site-packages', 'myapp.py')117- sys.modules['myapp'] = mod120+ here = os.path.abspath(os.path.dirname(__file__))121+ expected_prefix = os.path.join(here, 'test_apps')122+ real_prefix, sys.prefix = sys.prefix, expected_prefix123+ site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')124+ sys.path.append(site_packages)125 try:119- mod.app = flask.Flask(mod.__name__)120- self.assert_equal(mod.app.instance_path,121- os.path.join(expected_prefix, 'var',122- 'myapp-instance'))126+ import site_app127+ self.assert_equal(site_app.app.instance_path,128+ os.path.join(expected_prefix, 'var',129+ 'site_app-instance'))130 finally:124- sys.modules['myapp'] = None131+ sys.prefix = real_prefix132+ sys.path.remove(site_packages)133+ if 'site_app' in sys.modules:134+ del sys.modules['site_app']135 136 def test_installed_package_paths(self):127- import types128- expected_prefix = os.path.abspath('foo')129- package_path = os.path.join(expected_prefix, 'lib', 'python2.5',130- 'site-packages', 'myapp')131- mod = types.ModuleType('myapp')132- mod.__path__ = [package_path]133- mod.__file__ = os.path.join(package_path, '__init__.py')134- sys.modules['myapp'] = mod137+ here = os.path.abspath(os.path.dirname(__file__))138+ expected_prefix = os.path.join(here, 'test_apps')139+ real_prefix, sys.prefix = sys.prefix, expected_prefix140+ installed_path = os.path.join(expected_prefix, 'path')141+ sys.path.append(installed_path)142 try:136- mod.app = flask.Flask(mod.__name__)137- self.assert_equal(mod.app.instance_path,138- os.path.join(expected_prefix, 'var',139- 'myapp-instance'))143+ import installed_package144+ self.assert_equal(installed_package.app.instance_path,145+ os.path.join(expected_prefix, 'var',146+ 'installed_package-instance'))147 finally:141- sys.modules['myapp'] = None148+ sys.prefix = real_prefix149+ sys.path.remove(installed_path)150+ if 'installed_package' in sys.modules:151+ del sys.modules['installed_package']152 143- def test_prefix_installed_paths(self):144- import types145- expected_prefix = os.path.abspath(sys.prefix)146- package_path = os.path.join(expected_prefix, 'lib', 'python2.5',147- 'site-packages', 'myapp')148- mod = types.ModuleType('myapp')149- mod.__path__ = [package_path]150- mod.__file__ = os.path.join(package_path, '__init__.py')151- sys.modules['myapp'] = mod153+ def test_prefix_package_paths(self):154+ here = os.path.abspath(os.path.dirname(__file__))155+ expected_prefix = os.path.join(here, 'test_apps')156+ real_prefix, sys.prefix = sys.prefix, expected_prefix157+ site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')158+ sys.path.append(site_packages)159 try:153- mod.app = flask.Flask(mod.__name__)154- self.assert_equal(mod.app.instance_path,155- os.path.join(expected_prefix, 'var',156- 'myapp-instance'))160+ import site_package161+ self.assert_equal(site_package.app.instance_path,162+ os.path.join(expected_prefix, 'var',163+ 'site_package-instance'))164 finally:158- sys.modules['myapp'] = None165+ sys.prefix = real_prefix166+ sys.path.remove(site_packages)167+ if 'site_package' in sys.modules:168+ del sys.modules['site_package']169 170 def test_egg_installed_paths(self):161- import types162- expected_prefix = os.path.abspath(sys.prefix)163- package_path = os.path.join(expected_prefix, 'lib', 'python2.5',164- 'site-packages', 'MyApp.egg', 'myapp')165- mod = types.ModuleType('myapp')166- mod.__path__ = [package_path]167- mod.__file__ = os.path.join(package_path, '__init__.py')168- sys.modules['myapp'] = mod171+ here = os.path.abspath(os.path.dirname(__file__))172+ expected_prefix = os.path.join(here, 'test_apps')173+ real_prefix, sys.prefix = sys.prefix, expected_prefix174+ site_packages = os.path.join(expected_prefix, 'lib', 'python2.5', 'site-packages')175+ egg_path = os.path.join(site_packages, 'SiteEgg.egg')176+ sys.path.append(site_packages)177+ sys.path.append(egg_path)178 try:170- mod.app = flask.Flask(mod.__name__)171- self.assert_equal(mod.app.instance_path,172- os.path.join(expected_prefix, 'var',173- 'myapp-instance'))179+ import site_egg # in SiteEgg.egg180+ self.assert_equal(site_egg.app.instance_path,181+ os.path.join(expected_prefix, 'var',182+ 'site_egg-instance'))183 finally:175- sys.modules['myapp'] = None184+ sys.prefix = real_prefix185+ sys.path.remove(site_packages)186+ sys.path.remove(egg_path)187+ if 'site_egg' in sys.modules:188+ del sys.modules['site_egg']189 190 191 def suite():192 suite = unittest.TestSuite()3 unmodified lines