Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_find_file():
""" tests for the file finder """
assert utils.find_file("anything", []) is None
assert utils.find_file("anything", ["tests/templates"]) is None
assert utils.find_file("auth", ["tests/templates"]) is None
assert utils.find_file("index.html",
("tests/templates")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates", "tests/templates/auth")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates/auth", "tests/templates")
) == "tests/templates/auth/index.html"
def test_find_file():
""" tests for the file finder """
assert utils.find_file("anything", []) is None
assert utils.find_file("anything", ["tests/templates"]) is None
assert utils.find_file("auth", ["tests/templates"]) is None
assert utils.find_file("index.html",
("tests/templates")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates", "tests/templates/auth")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates/auth", "tests/templates")
) == "tests/templates/auth/index.html"
def test_find_file():
""" tests for the file finder """
assert utils.find_file("anything", []) is None
assert utils.find_file("anything", ["tests/templates"]) is None
assert utils.find_file("auth", ["tests/templates"]) is None
assert utils.find_file("index.html",
("tests/templates")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates", "tests/templates/auth")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates/auth", "tests/templates")
) == "tests/templates/auth/index.html"
def test_find_file():
""" tests for the file finder """
assert utils.find_file("anything", []) is None
assert utils.find_file("anything", ["tests/templates"]) is None
assert utils.find_file("auth", ["tests/templates"]) is None
assert utils.find_file("index.html",
("tests/templates")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates", "tests/templates/auth")
) == "tests/templates/index.html"
assert utils.find_file("index.html",
("tests/templates/auth", "tests/templates")
) == "tests/templates/auth/index.html"
path -- the image's filename
search_path -- a search path for the image (string or list of strings)
"""
if path.startswith('@'):
return StaticImage(path[1:], search_path)
if path.startswith('//') or '://' in path:
return RemoteImage(path, search_path)
if os.path.isabs(path):
file_path = utils.find_file(os.path.relpath(
path, '/'), config.content_folder)
else:
file_path = utils.find_file(path, search_path)
if not file_path:
return ImageNotFound(path, search_path)
record = _get_asset(file_path)
if record.is_asset:
return FileAsset(record, search_path)
return LocalImage(record, search_path)
""" Get an Image object. If the path is given as absolute, it will be
relative to the content directory; otherwise it will be relative to the
search path.
path -- the image's filename
search_path -- a search path for the image (string or list of strings)
"""
if path.startswith('@'):
return StaticImage(path[1:], search_path)
if path.startswith('//') or '://' in path:
return RemoteImage(path, search_path)
if os.path.isabs(path):
file_path = utils.find_file(os.path.relpath(
path, '/'), config.content_folder)
else:
file_path = utils.find_file(path, search_path)
if not file_path:
return ImageNotFound(path, search_path)
record = _get_asset(file_path)
if record.is_asset:
return FileAsset(record, search_path)
return LocalImage(record, search_path)
def _get_image(path: str, search_path: typing.Tuple[str, ...]) -> Image:
if path.startswith('@'):
return StaticImage(path[1:], search_path)
if path.startswith('//') or '://' in path:
return RemoteImage(path, search_path)
if os.path.isabs(path):
file_path = utils.find_file(os.path.relpath(
path, '/'), config.content_folder)
else:
file_path = utils.find_file(path, search_path)
if not file_path:
return ImageNotFound(path, search_path)
record = _get_asset(file_path)
if record.is_asset:
return FileAsset(record, search_path)
return LocalImage(record, search_path)
def _get_image(path: str, search_path: typing.Tuple[str, ...]) -> Image:
if path.startswith('@'):
return StaticImage(path[1:], search_path)
if path.startswith('//') or '://' in path:
return RemoteImage(path, search_path)
if os.path.isabs(path):
file_path = utils.find_file(os.path.relpath(
path, '/'), config.content_folder)
else:
file_path = utils.find_file(path, search_path)
if not file_path:
return ImageNotFound(path, search_path)
record = _get_asset(file_path)
if record.is_asset:
return FileAsset(record, search_path)
return LocalImage(record, search_path)