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

Fix Flake8 violations for files in the test/ directory #1096

Merged
merged 43 commits into from
Mar 11, 2022

Conversation

LucyJimenez
Copy link
Contributor

@LucyJimenez LucyJimenez commented Mar 3, 2022

xref #1042

Fix pep8 issues on:

  • test_util.py
  • test_subprocess.py

@LucyJimenez LucyJimenez marked this pull request as draft March 4, 2022 01:24
@@ -1,18 +1,15 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import io
import locale
import locale # noqa F401 imported but unused
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The locale library is not used and in the code of the file it is not found anywhere else, but when I remove it I get an error in AppVeyor CI. Any idea why this happens?

Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to it's own PR, so we can isolate and see the CI failure without other changes.

Copy link
Member

Choose a reason for hiding this comment

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

This is not addressed.

@LucyJimenez LucyJimenez marked this pull request as ready for review March 4, 2022 11:51
@@ -34,7 +34,7 @@ def test_timeout():
sys.stdout.flush()
sys.stderr.flush()
subprocess.call([sys.executable, "-c",
"import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"])
"import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"]) # noqa E501 line too long
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason why this can't be splitted in multiple lines.

Copy link
Contributor Author

@LucyJimenez LucyJimenez Mar 7, 2022

Choose a reason for hiding this comment

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

I'm not sure why it is not easy to split this line. I tried a couple of things, and it doesn’t work. For example:
Option 1:
image
Option 2:
image

Could you please help me?

Copy link
Member

Choose a reason for hiding this comment

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

This is Python code as a string. It needs to be valid Python code when converted to a .py file. And this is clearly not, as you have a multiline string with single quotes.

@@ -1,18 +1,15 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import io
import locale
import locale # noqa F401 imported but unused
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to it's own PR, so we can isolate and see the CI failure without other changes.

@LucyJimenez
Copy link
Contributor Author

@datapythonista I'm going to slip this PR to get more info about the errors.

@datapythonista
Copy link
Member

@datapythonista I'm going to slip this PR to get more info about the errors.

Not sure what you mean, but the line too long just needs to be split and for the locale import, you can just have a message that things fail if removed, and create and link an issue to check why.

@LucyJimenez
Copy link
Contributor Author

@datapythonista The PR is ready for your review; thanks!

@@ -1,18 +1,15 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import io
import locale
import locale # noqa F401 imported but unused
Copy link
Member

Choose a reason for hiding this comment

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

This is not addressed.

@@ -34,7 +34,8 @@ def test_timeout():
sys.stdout.flush()
sys.stderr.flush()
subprocess.call([sys.executable, "-c",
"import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"])
"import sys, subprocess; subprocess.call([sys.executable, '-c', \
'import time; time.sleep(360)'])"])
Copy link
Member

Choose a reason for hiding this comment

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

This is quite hard to read. The code itself is easy to read, we should split it in a way that makes things more clear.

I think I'd have the parameters of call in their own line: sys.executable, '-c', 'import time; time.sleep(360)'.

And I would avoid using a backslash, as this makes things harder to read, besides introducing spaces. I'd just have one string per line, which Python will automatically concatenate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much for all the explanations. It was enlightening, and I tried to apply your comments to get a better result.

@LucyJimenez
Copy link
Contributor Author

@datapythonista The CI / test (pypy-3.8) has been running for ~50 minutes. Is it normal?

image

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

I will have a look at the pypy build if it happens again.

subprocess.call([sys.executable, "-c",
"import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"])
subprocess.call([sys.executable, "-c", "import sys, subprocess;"
"subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"])
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this changed, but this is still not very readable. This is much more readable:

subprocess.call([
    sys.executable,
    "-c",
    "import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"
])

And if still too long:

subprocess.call([
    sys.executable,
    "-c",
    "import sys, subprocess; subprocess.call("
    "[sys.executable, -c', import time; time.sleep(360)'])"
])

Or something similar, where is clear which are the parameters of each function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I'll put it in the code.

Copy link
Contributor Author

@LucyJimenez LucyJimenez Mar 9, 2022

Choose a reason for hiding this comment

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

This option works well, but is too long E501 line too long (101 > 99 characters)

subprocess.call([
    sys.executable,
    "-c",
    "import sys, subprocess; subprocess.call([sys.executable, '-c', 'import time; time.sleep(360)'])"
])

The second option was implemented but it was not working.

subprocess.call([
   sys.executable,
   "-c",
   "import sys, subprocess; subprocess.call("
   "[sys.executable, -c', import time; time.sleep(360)'])"
])

@datapythonista what is the best thing to do in this case?

sys.executable,
"-c",
"import sys, subprocess; subprocess.call("
"[sys.executable, -c', import time; time.sleep(360)'])"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"[sys.executable, -c', import time; time.sleep(360)'])"
"[sys.executable, '-c', import time; time.sleep(360)'])"

A quote is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@datapythonista I fix the quote missing, but it is still not working. Do you think I could use this code instead?

subprocess.call([sys.executable, "-c",
    "import sys, subprocess; subprocess.call(\
    [sys.executable, '-c', 'import time; time.sleep(360)'])"])

Copy link
Member

Choose a reason for hiding this comment

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

The backslash is irrelevant, and as I mentioned, a discouraged practice in Python. There is another quote missing:

[sys.executable, '-c', import time; time.sleep(360)']
[sys.executable, '-c', 'import time; time.sleep(360)']

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

There are conflicts that need to be solved, and one comment.

@@ -1,18 +1,15 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import io
import locale
import locale # noqa F401 imported but unused see #1106
Copy link
Member

Choose a reason for hiding this comment

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

The errors in #1106 seem unrelated to this. Can you try to remove this again, and see if the error is relevant this time please.

Copy link
Contributor Author

@LucyJimenez LucyJimenez Mar 10, 2022

Choose a reason for hiding this comment

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

I removed the import locale and there are errors for the CI / test (ubuntu-latest, pypy-3.7) (pull_request) and the CI / test (ubuntu-latest, pypy-3.8) (pull_request). The tests are passed for the test/test_subprocess.py and test/test_util.py files in both cases.

image

image

The AppVeyor is not presenting errors.

Copy link
Member

Choose a reason for hiding this comment

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

These failures seem unrelated. Can you just remove the locale import from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@LucyJimenez
Copy link
Contributor Author

@datapythonista, I think now this PR is ready for the last review :)

@datapythonista datapythonista merged commit d92fc39 into airspeed-velocity:master Mar 11, 2022
@datapythonista
Copy link
Member

Thanks @LucyJimenez

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

Successfully merging this pull request may close these issues.

2 participants