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_compress():
compressor = Compressor(use_brotli=False, use_gzip=False)
assert [] == list(compressor.compress("tests/test_files/static/styles.css"))
def test_compressed_effectively_no_orig_size():
compressor = Compressor(quiet=True)
assert not compressor.is_compressed_effectively(
"test_encoding", "test_path", 0, "test_data"
)
def test_with_custom_extensions():
compressor = Compressor(extensions=["jpg"], quiet=True)
assert compressor.extension_re == re.compile(r"\.(jpg)$", re.IGNORECASE)
def test_custom_log():
compressor = Compressor(log="test")
assert compressor.log == "test"
def create_compressor(self, **kwargs):
return Compressor(**kwargs)
def main(root, **kwargs):
compressor = Compressor(**kwargs)
for dirpath, dirs, files in os.walk(root):
for filename in files:
if compressor.should_compress(filename):
path = os.path.join(dirpath, filename)
for compressed in compressor.compress(path):
pass
help="Don't produce gzip '.gz' files",
action="store_false",
dest="use_gzip",
)
parser.add_argument(
"--no-brotli",
help="Don't produce brotli '.br' files",
action="store_false",
dest="use_brotli",
)
parser.add_argument("root", help="Path root from which to search for files")
parser.add_argument(
"extensions",
nargs="*",
help="File extensions to exclude from compression "
"(default: {})".format(", ".join(Compressor.SKIP_COMPRESS_EXTENSIONS)),
default=Compressor.SKIP_COMPRESS_EXTENSIONS,
)
args = parser.parse_args()
main(**vars(args))