Skip to content
Myr

Merge branch '1.0.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents afd6250, 043443d · Browse files · 6 files+59 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+59 added−28 removed

  • tests:+11 added−13 removed
  • other:+48 added−15 removed

6 files+59 added−28 removed

modified:docs/tutorial/tests.rst+1 added-1 removed
186 unmodified lines
187188 with pytest.raises(sqlite3.ProgrammingError) as e:189 db.execute('SELECT 1')190191 assert 'closed' in str(e)191 assert 'closed' in str(e.value)192193The ``init-db`` command should call the ``init_db`` function and output194a message.195
366 unmodified lines
modified:examples/tutorial/tests/test_db.py+1 added-1 removed
11 unmodified lines
1213 with pytest.raises(sqlite3.ProgrammingError) as e:14 db.execute("SELECT 1")1516 assert "closed" in str(e)16 assert "closed" in str(e.value)171819def test_init_db_command(runner, monkeypatch):20 class Recorder(object):
9 unmodified lines
modified:src/flask/helpers.py+46 added-14 removed
608 unmodified lines
609 filenames = {610 "filename": unicodedata.normalize("NFKD", attachment_filename).encode(611 "ascii", "ignore"612 ),613 'filename*': "UTF-8''%s" % url_quote(attachment_filename, safe=b""),613 "filename*": "UTF-8''%s" % url_quote(attachment_filename, safe=b""),614 }615 else:616 filenames = {"filename": attachment_filename}617
228 unmodified lines
846 % loader.__class__.__name__847 )848849850def find_package(import_name):851 """Finds a package and returns the prefix (or None if the package is852 not installed) as well as the folder that contains the package or853 module as a tuple. The package path returned is the module that would854 have to be added to the pythonpath in order to make it possible to855 import the module. The prefix is the path below which a UNIX like856 folder structure exists (lib, share etc.).857 """858 root_mod_name = import_name.split(".")[0]850def _find_package_path(root_mod_name):851 """Find the path where the module's root exists in"""852 if sys.version_info >= (3, 4):853 import importlib.util854855 try:856 spec = importlib.util.find_spec(root_mod_name)857 if spec is None:858 raise ValueError("not found")859 # ImportError: the machinery told us it does not exist860 # ValueError:861 # - the module name was invalid862 # - the module name is __main__863 # - *we* raised `ValueError` due to `spec` being `None`864 except (ImportError, ValueError):865 pass # handled below866 else:867 # namespace package868 if spec.origin in {"namespace", None}:869 return os.path.dirname(next(iter(spec.submodule_search_locations)))870 # a package (with __init__.py)871 elif spec.submodule_search_locations:872 return os.path.dirname(os.path.dirname(spec.origin))873 # just a normal module874 else:875 return os.path.dirname(spec.origin)876877 # we were unable to find the `package_path` using PEP 451 loaders878 loader = pkgutil.get_loader(root_mod_name)860 if loader is None or import_name == "__main__":879 if loader is None or root_mod_name == "__main__":880 # import name is not found, or interactive/main module862 package_path = os.getcwd()881 return os.getcwd()882 else:883 # For .egg, zipimporter does not have get_filename until Python 2.7.884 if hasattr(loader, "get_filename"):885 filename = loader.get_filename(root_mod_name)
5 unmodified lines
891 # At least one loader is missing both get_filename and archive:892 # Google App Engine's HardenedModulesHook893 #894 # Fall back to imports.876 __import__(import_name)877 filename = sys.modules[import_name].__file__895 __import__(root_mod_name)896 filename = sys.modules[root_mod_name].__file__897 package_path = os.path.abspath(os.path.dirname(filename))898899 # In case the root module is a package we need to chop of the900 # rightmost part. This needs to go through a helper function901 # because of python 3.3 namespace packages.902 if _matching_loader_thinks_module_is_package(loader, root_mod_name):903 package_path = os.path.dirname(package_path)904905 return package_path906907908def find_package(import_name):909 """Finds a package and returns the prefix (or None if the package is910 not installed) as well as the folder that contains the package or911 module as a tuple. The package path returned is the module that would912 have to be added to the pythonpath in order to make it possible to913 import the module. The prefix is the path below which a UNIX like914 folder structure exists (lib, share etc.).915 """916 root_mod_name, _, _ = import_name.partition(".")917 package_path = _find_package_path(root_mod_name)918 site_parent, site_folder = os.path.split(package_path)919 py_prefix = os.path.abspath(sys.prefix)920 if package_path.startswith(py_prefix):921 return py_prefix, package_path
232 unmodified lines
modified:tests/test_basic.py+8 added-10 removed
1218 unmodified lines
1219 c = app.test_client()12201221 with pytest.raises(TypeError) as e:1222 c.get("/none")1223 assert "returned None" in str(e.value)12241224 assert "returned None" in str(e)12251225 with pytest.raises(TypeError) as e:1226 c.get("/small_tuple")1227 assert "tuple must have the form" in str(e.value)12281229 assert "tuple must have the form" in str(e)12301229 pytest.raises(TypeError, c.get, "/large_tuple")12301231 with pytest.raises(TypeError) as e:1232 c.get("/bad_type")1233 assert "it was a bool" in str(e.value)12341236 assert "object is not callable" not in str(e)1237 assert "it was a bool" in str(e)12381235 pytest.raises(TypeError, c.get, "/bad_wsgi")123612371238def test_make_response(app, req_ctx):
392 unmodified lines
1631 @app.route("/foo")1632 def broken():1633 return "Meh"16341639 assert "A setup function was called" in str(e)1635 assert "A setup function was called" in str(e.value)16361637 app.debug = False16381639 @app.route("/foo")
46 unmodified lines
16861687 with client:1688 with pytest.raises(AssertionError) as e:1689 client.post("/foo", data={})1694 assert "http://localhost/foo/" in str(e)1695 assert ("Make sure to directly send your POST-request to this URL") in str(e)1690 assert "http://localhost/foo/" in str(e.value)1691 assert ("Make sure to directly send your POST-request to this URL") in str(1692 e.value1693 )16941695 rv = client.get("/foo", data={}, follow_redirects=True)1696 assert rv.data == b"success"1697
270 unmodified lines
modified:tests/test_helpers.py+2 added-2 removed
481 unmodified lines
482483 def test_send_file_object_without_mimetype(self, app, req_ctx):484 with pytest.raises(ValueError) as excinfo:485 flask.send_file(StringIO("LOL"))486 assert "Unable to infer MIME-type" in str(excinfo)487 assert "no filename is available" in str(excinfo)486 assert "Unable to infer MIME-type" in str(excinfo.value)487 assert "no filename is available" in str(excinfo.value)488489 flask.send_file(StringIO("LOL"), attachment_filename="filename")490491 def test_send_file_object(self, app, req_ctx):
553 unmodified lines
modified:CHANGES.rst+1 added
92 unmodified lines
93 outside debug mode, so error handlers can still access it. This94 requires upgrading to Werkzeug 0.15.5. :issue:`3249`95- ``send_file`` url quotes the ":" and "/" characters for more96 compatible UTF-8 filename support in some browsers. :issue:`3074`97- Fixes for PEP451 import loaders and pytest 5.x. :issue:`3275`9899100Version 1.0.3101-------------
881 unmodified lines