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_make_helpful_exception(_compressed_manifest_storage):
class TriggerException(HashedFilesMixin):
def exists(self, path):
return False
exception = None
try:
TriggerException().hashed_name("/missing/file.png")
except ValueError as e:
exception = e
helpful_exception = HelpfulExceptionMixin().make_helpful_exception(
exception, "styles/app.css"
)
assert isinstance(helpful_exception, MissingFileError)
message = self.ERROR_MSG.format(
orig_message=message,
filename=name,
missing=match.group(1),
ext=extension,
)
exception = MissingFileError(message)
return exception
class MissingFileError(ValueError):
pass
class CompressedManifestStaticFilesStorage(
HelpfulExceptionMixin, ManifestStaticFilesStorage
):
"""
Extends ManifestStaticFilesStorage instance to create compressed versions
of its output files and, optionally, to delete the non-hashed files (i.e.
those without the hash in their name)
"""
_new_files = None
def post_process(self, *args, **kwargs):
files = super(CompressedManifestStaticFilesStorage, self).post_process(
*args, **kwargs
)
if not kwargs.get("dry_run"):
files = self.post_process_with_compression(files)
return files
def post_process(self, *args, **kwargs):
files = super(HelpfulExceptionMixin, self).post_process(*args, **kwargs)
for name, hashed_name, processed in files:
if isinstance(processed, Exception):
processed = self.make_helpful_exception(processed, name)
yield name, hashed_name, processed