Skip to content

[Tests] Cleanup the tests of argparse. #11750

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

Closed

Conversation

hobbestigrou
Copy link

Remove useless import, remove useless assignment variables and be
pep8 compliant.

Remove useless import, remove useless assignment variables and be
pep8 compliant.
@hobbestigrou hobbestigrou force-pushed the cleanup_test_argparse branch from 113bb22 to ce8677a Compare February 3, 2019 10:11
Copy link
Contributor

@SylvainDe SylvainDe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few details.
As a general comment, one of the very important part of PEP 8 is at the very beginning:
"A Foolish Consistency is the Hobgoblin of Little Minds" (...) "However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. " followed by "good reasons to ignore a particular guideline".

@@ -471,8 +479,7 @@ class TestOptionalsAlternatePrefixCharsMultipleShortArgs(ParserTestCase):
'-xyz',
'+x',
'-y',
'+xyz',
]
'+xyz']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original code is more idiomatic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @SylvainDe

argument_group_signatures = TestHelpBiggerOptionals.argument_group_signatures
parser_signature = TestHelpBiggerOptionals.parser_signature
argument_signatures = TestHelpBiggerOptionals.argument_signatures
argument_group_signatures = TestHelpBiggerOptionals\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked more beautiful before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this change is good. IMO pep8 analyze should fail if we maintain the old style. Why never fail?

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @SylvainDe. Sometimes, fix pep8 problems will not be a good improve.
But core dev reviewers have the last word. :-)

Please review why the test are fail

@@ -425,7 +431,9 @@ class TestOptionalsAlternatePrefixChars(ParserTestCase):
Sig('::bar'),
Sig('/baz', action='store_const', const=42),
]
failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz', '-h', '--help', '+h', '::help', '/help']
failures = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is better use the first line to put values, and not start on new line. e.g.:

failures = [ '--bar', '-fbar', '-b B', 'B', '-f', '--bar B',
'-baz', '-h', '--help', '+h', '::help', '/help']

@@ -471,8 +479,7 @@ class TestOptionalsAlternatePrefixCharsMultipleShortArgs(ParserTestCase):
'-xyz',
'+x',
'-y',
'+xyz',
]
'+xyz']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @SylvainDe

self.assertRaises(ArgumentParserError, parser.parse_args,
['-y', 'Y', '-z', 'Z'])
self.assertRaises(
ArgumentParserError, parser.parse_args, ['-y', 'Y', '-z', 'Z'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before is better.

argument_group_signatures = TestHelpBiggerOptionals.argument_group_signatures
parser_signature = TestHelpBiggerOptionals.parser_signature
argument_signatures = TestHelpBiggerOptionals.argument_signatures
argument_group_signatures = TestHelpBiggerOptionals\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this change is good. IMO pep8 analyze should fail if we maintain the old style. Why never fail?

class TestHelpVersionAction(HelpTestCase):
"""Test the default help for the version action"""

parser_signature = Sig(prog='PROG', description='description')
argument_signatures = [Sig('-V', '--version', action='version', version='3.6')]
argument_signatures = [Sig(
'-V', '--version', action='version', version='3.6')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same of the comments above.

@csabella
Copy link
Contributor

csabella commented Mar 4, 2019

Thanks for the work, but we don't generally make bulk changes like this. It generates churn in the codebase, and has the risk of inadvertently changing the meaning of the tests, to little actual benefit. Instead we modernize tests when we touch them for other reasons and are in a position to confirm that the changes do not change the meaning of the tests. (I realize that for most of your changes the meaning is trivially preserved...but when you make a lot of changes you are almost certain to make some mistakes...thus the resistance to doing bulk updates.)

As you can see, none of the continuous integration tests passed, which reinforces the fact that this change isn't as trivial as it may appear. For example, from the Travis check:

======================================================================
FAIL: test_subparser_title_help (test.test_argparse.TestAddSubparsers)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/python/cpython/Lib/test/test_argparse.py", line 2070, in test_subparser_title_help
    self.assertEqual(parser.format_usage(),
AssertionError: 'usage: PROG [-h] [--foo] bar\n' != 'usage: PROG [-h] [--foo] bar {1,2} ...\n'
- usage: PROG [-h] [--foo] bar
+ usage: PROG [-h] [--foo] bar {1,2} ...
?                             ++++++++++
----------------------------------------------------------------------

@csabella csabella closed this Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants