-
Notifications
You must be signed in to change notification settings - Fork 181
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
Fix Flake8 violations for files in the test/ directory #1096
Conversation
This reverts commit 2af36bf.
test/test_util.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not addressed.
test/test_subprocess.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
test/test_util.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
@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 |
@datapythonista The PR is ready for your review; thanks! |
test/test_util.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not addressed.
test/test_subprocess.py
Outdated
@@ -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)'])"]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@datapythonista The CI / test (pypy-3.8) has been running for ~50 minutes. Is it normal? |
There was a problem hiding this 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.
test/test_subprocess.py
Outdated
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)'])"]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
test/test_subprocess.py
Outdated
sys.executable, | ||
"-c", | ||
"import sys, subprocess; subprocess.call(" | ||
"[sys.executable, -c', import time; time.sleep(360)'])" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"[sys.executable, -c', import time; time.sleep(360)'])" | |
"[sys.executable, '-c', import time; time.sleep(360)'])" |
A quote is missing
There was a problem hiding this comment.
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)'])"])
There was a problem hiding this comment.
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)']
There was a problem hiding this 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.
test/test_util.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
The AppVeyor is not presenting errors.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@datapythonista, I think now this PR is ready for the last review :) |
Thanks @LucyJimenez |
xref #1042
Fix pep8 issues on:
test_util.py
test_subprocess.py