Esempio n. 1
0
def test_prepare_exec_for_file(test_apps):
    """Expect the correct path to be set and the correct module name to be returned.

    :func:`prepare_exec_for_file` has a side effect, where
    the parent directory of given file is added to `sys.path`.
    """
    realpath = os.path.realpath('/tmp/share/test.py')
    dirname = os.path.dirname(realpath)
    assert prepare_exec_for_file('/tmp/share/test.py') == 'test'
    assert dirname in sys.path

    realpath = os.path.realpath('/tmp/share/__init__.py')
    dirname = os.path.dirname(os.path.dirname(realpath))
    assert prepare_exec_for_file('/tmp/share/__init__.py') == 'share'
    assert dirname in sys.path

    with pytest.raises(NoAppException):
        prepare_exec_for_file('/tmp/share/test.txt')
Esempio n. 2
0
def test_find_default_import_path(test_apps, monkeypatch, tmpdir):
    """Test of find_default_import_path."""
    monkeypatch.delitem(os.environ, 'FLASK_APP', raising=False)
    assert find_default_import_path() == None
    monkeypatch.setitem(os.environ, 'FLASK_APP', 'notanapp')
    assert find_default_import_path() == 'notanapp'
    tmpfile = tmpdir.join('testapp.py')
    tmpfile.write('')
    monkeypatch.setitem(os.environ, 'FLASK_APP', str(tmpfile))
    expect_rv = prepare_exec_for_file(str(tmpfile))
    assert find_default_import_path() == expect_rv
Esempio n. 3
0
 def load_app(self):
     if self.create_app is None and self.app_import_path is None:
         if "FRASCO_APP" in os.environ:
             self.app_import_path = os.environ["FRASCO_APP"]
             if os.path.isfile(self.app_import_path):
                 self.app_import_path = prepare_exec_for_file(app)
             elif '.' not in sys.path:
                 sys.path.insert(0, '.')
         elif os.path.exists("app.py"):
             self.app_import_path = "app"
         elif os.path.exists("app.yml"):
             self.create_app = lambda i: create_app_from_cwd()
     return super(FrascoScriptInfo, self).load_app()
Esempio n. 4
0
def test_prepare_exec_for_file(test_apps):
    assert prepare_exec_for_file('test.py') == 'test'
    assert prepare_exec_for_file('/usr/share/__init__.py') == 'share'
    with pytest.raises(NoAppException):
        prepare_exec_for_file('test.txt')