Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for known sub-optimal minifications #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions test/test_failing_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Tests that are expected to fail currently
"""
import ast

import pytest

from python_minifier import UnstableMinification, minify, unparse


@pytest.mark.xfail(reason="Known unstable minification")
def test_unstable_minification():
"""
Known unstable minifications that need to be fixed
"""

with pytest.raises(UnstableMinification):
minify('with (x := await a, y := await b): pass')


@pytest.mark.xfail(reason="Known un-optimal minification")
def test_name_following_literal_number():
"""
Name following literal number without a space

This is a syntax warning in recent versions of Python,
perhaps we should consider making this an optional minification
"""

source = 'True if 0in x else False'
assert source == unparse(ast.parse(source))


@pytest.mark.xfail(reason="Known un-optimal minification")
def test_generator_parentheses():
"""
Generator expression parentheses

Generator expressions are not always required to be parenthesized,
but we currently always parenthesize them
"""

source = 'sum(A for A in A)'
assert source == unparse(ast.parse(source))


@pytest.mark.xfail(reason="Known un-optimal minification")
def test_generator_in_arglist():
"""
Expanding a generator expression in an function call argument list
"""

source = 'A(*[B for b in a])'
assert source == unparse(ast.parse(source))


@pytest.mark.xfail(reason="Known un-optimal minification")
def test_tuple_in_for_target():
"""
A tuple in a for target has unnecessary parentheses
"""

source = 'for A,B in C:pass'
assert source == unparse(ast.parse(source))


@pytest.mark.xfail(reason="Known un-optimal minification")
def test_string_literal_style():
"""
String literals don't choose the smallest quote style
"""

source = '''my_string="""This


is


my


multi-line


string


"""
'''
assert source == unparse(ast.parse(source))