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

Improve indentation tests #3651

Closed
rlaverde opened this issue Nov 4, 2016 · 3 comments
Closed

Improve indentation tests #3651

rlaverde opened this issue Nov 4, 2016 · 3 comments

Comments

@rlaverde
Copy link
Member

rlaverde commented Nov 4, 2016

Indentation tests only test for indentation using spaces, and It's necessary to also test for indentation using tabs (that is partially broken #3508)

I'm thinking about using parametrize fixture to make test support several options

and I have consider different ways to organize test:

1: Each test will have parametrize options for tabs and spaces:

@pytest.mark.parametrize("indent_chars, text_input, expected", [
    ("    ", "\ndef function():\n", "\ndef function():\n    "),
    ("\t", "\ndef function():\n", "\ndef function():\n\t"),
])
def test_def_with_newline(indent_chars, text_input, expected):
    text = get_indent_fix(text_input, indent_chars)
    assert text == expected, repr(text)
  1. Each test will have parametrize options for tabs and spaces, but strings will be generated into the test:
@pytest.mark.parametrize("indent_chars", [
    ("    "), ("\t"),
])
def test_def_with_newline(indent_chars):
    text = get_indent_fix("\ndef function():\n", indent_chars)
    assert text == "\ndef function():\n" + indent_chars, repr(text)
  1. will be one test or maybe two (tabs and spaces) with several parametrized options:
@pytest.mark.parametrize("indent_chars, text_input, expected", [
    ("    ", "\ndef function():\n", "\ndef function():\n    "),
    ("\t", "\ndef function():\n", "\ndef function():\n\t"),

    ("    ","def function():\n    print []\n" , "def function():\n\tprint []\n    "),
    ("\t","def function():\n\tprint []\n" , "def function():\n\tprint []\n\t"),
])
def test_indentation(indent_chars, text_input, expected):
    text = get_indent_fix(text_input, indent_chars)
    assert text == expected, repr(text)

which option could be the best?

cc: @Nodd @goanpeca

@ccordoba12
Copy link
Member

Was this already fixed in #3680 @rlaverde?

@ccordoba12
Copy link
Member

Sorry, #3663?

@rlaverde
Copy link
Member Author

rlaverde commented Nov 23, 2016

Yes, I implemented the third way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants