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 all flake8 violations in the test/ directory #1021

Merged
merged 18 commits into from
Feb 10, 2022

Conversation

dorothykiz1
Copy link
Contributor

@dorothykiz1 dorothykiz1 commented Feb 7, 2022

closes 11

Fix flake8 violations for files below;

  1. test/conftest.py
  2. test/test_dev.py
  3. test/test_feed.py
  4. .github/workflows/ci.yml
  5. setup.cfg

run: flake8 test/conftest.py test/test_dev.py test/test_feed.py test/test_repo_template/asv_test_repo/__init__.py
Copy link
Member

Choose a reason for hiding this comment

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

What is the goal of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted flake8 to check the files I changed but I will remove this as it's not necessary

@@ -3,4 +3,4 @@

from __future__ import absolute_import, division, unicode_literals, print_function

dummy_value = {dummy_value}
dummy_value = {dummy_value} # noqa
Copy link
Member

Choose a reason for hiding this comment

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

For a noqa we should have the error code you want to ignore, not all them. And also a comment explaining why we want flake8 to ignore the problem here, instead of fixing the error.

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, Marc, Let me add this asap to be more descriptive

@datapythonista
Copy link
Member

Thanks for the PR. Added couple of comments, and you also have conflicts to fix.

@dorothykiz1
Copy link
Contributor Author

@datapythonista this PR is ready for your review will await your guidance

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.

Besides the comments, you will have to fix the conflicts

test/test_dev.py Outdated
import re
from os.path import abspath, dirname, join, relpath
import shutil
import pytest

import six
import six # noqa
Copy link
Member

Choose a reason for hiding this comment

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

Why is this? In case it's really needed you need the error code to skip and the reason.

@@ -3,4 +3,4 @@

from __future__ import absolute_import, division, unicode_literals, print_function

dummy_value = {dummy_value}
dummy_value = {dummy_value} # noqa:F821 dummy_value not defined but used
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 create an issue for this, and link it here? It may be worth running this test file to see why this test file is not failing in the CI.

@dorothykiz1
Copy link
Contributor Author

@datapythonista this PR is ready for your review again

test/test_dev.py Outdated
import re
from os.path import abspath, dirname, join, relpath
import shutil
import pytest

import six
import six # noqa F401 'six' 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.

I don't see why six needs to be imported if it's not used. What's the error?

Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Feb 9, 2022

Choose a reason for hiding this comment

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

It is only the flake8 check throws an error (F401 'six' imported but unused)
but the tests pass. its the reason I had removed it completely earlier

Copy link
Member

Choose a reason for hiding this comment

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

We already discussed this case few times. What we did was:

  • Remove the import
  • If something fails in the test, we check the test failure, we try to understand why this import needs to be here, and we add a the noqa with the error code to skip, and a comment for other devs to know
  • If it's difficult for you to understand the error, as often requires a lot of experience, just find the error, post it here, so we can discuss and you can learn about it
  • Just adding the error from flake8 doesn't add much value. The first question I'll ask myself if I see this code is "why the import hasn't been removed it it's unused". This is what the code/comment should tell us. Regardless of flake8, why we are importing the module if it's not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure let me try this

@@ -3,4 +3,4 @@

from __future__ import absolute_import, division, unicode_literals, print_function

dummy_value = {dummy_value}
dummy_value = {dummy_value} # noqa:F821 see #1023 Bug: dummy_value is not defined
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for creating the issue. Did you check why this doesn't raise an error in the CI?

Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Feb 9, 2022

Choose a reason for hiding this comment

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

@datapythonista Am thinking it should be raised in the Ci but it is not, its only flakes 8 that is catching it.

Copy link
Member

Choose a reason for hiding this comment

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

Also what I'm thinking. But the CI is green (both in this PR and in master). So, we are missing something. Can you have a look at what's going on please. If you don't find out easily, please let me know what's your approach to find out and we can discuss about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me try to find out, had run pytest on all the files but it's still quite abstract.

FAILED test/test_update.py::test_update_simple[hg] - FileNotFoundError: [Errno 2] No such file or directory: 'hg'
ERROR test/test_repo.py::test_get_branch_commits[hg] - FileNotFoundError: [Errno 2] No such file or directory: 'hg'
ERROR test/test_repo.py::test_get_new_branch_commits[hg-all] - FileNotFoundError: [Errno 2] No such file or directory: 'hg'
ERROR test/test_repo.py::test_get_new_branch_commits[hg-new] - FileNotFoundError: [Errno 2] No such file or directory: 'hg'
ERROR test/test_repo.py::test_get_new_branch_commits[hg-no-new] - FileNotFoundError: [Errno 2] No such file or directory: 'hg'
ERROR test/test_repo.py::test_get_new_branch_commits[hg-new-branch-added-in-config] - FileNotFoundError: [Errno 2] No such file or dire..

Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Feb 9, 2022

Choose a reason for hiding this comment

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

@datapythonista kindly share your thoughts on this

when I run rgrep -I "dummy_value" *I can see the variable dummy_value is being used and its imported from the file in question.

def track_find_test(n):
import asv_test_repo

return asv_test_repo.dummy_value[n - 1]

track_find_test.params = [1, 2]

def time_find_test_timeout():
import asv_test_repo, time
if asv_test_repo.dummy_value[1] < 0:
time.sleep(100)

@@ -16,4 +16,4 @@ jobs:
run: flake8 . || true # preventing CI failing while flake8 issues exist

- name: flake8 validating correct file(s)
run: flake8 asv/main.py asv/repo.py asv/results.py asv/runner.py asv/statistics.py asv/step_detect.py asv/util.py test/benchmark/ asv/__init__.py asv/benchmarks.py asv/config.py asv/benchmark.py
run: flake8 asv/main.py asv/repo.py asv/results.py asv/runner.py asv/statistics.py asv/step_detect.py asv/util.py test/benchmark/ asv/__init__.py asv/benchmarks.py asv/config.py asv/benchmark.py test/conftest.py test/test_dev.py test/test_feed.py test/test_repo_template/asv_test_repo/__init__.py
Copy link
Member

Choose a reason for hiding this comment

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

Maybe time to split this in two lines, this is becoming unreadable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure,will do this

@dorothykiz1
Copy link
Contributor Author

Hello @datapythonista this PR is ready for your review again

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.

Thanks @dorothykiz1, this looks great, and will be very useful.

I added couple of minor comments on things that can help, but other than that looks perfect.


- name: flake8 validating correct file(s)
run: flake8 asv/main.py asv/repo.py asv/results.py asv/runner.py asv/statistics.py asv/step_detect.py asv/util.py test/benchmark/ asv/__init__.py asv/benchmarks.py asv/config.py asv/benchmark.py
run: flake8 . || true # preventing CI failing while flake8 issues exist
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the || true anymore, since all the files that would make the CI fail are now excluded.

When you do that, maybe you can also simplify the name of the job now, to just flake8 or similar, since there is only one now, and it's not so complex to understand what each does.

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, let me do this

setup.cfg Outdated
@@ -1,6 +1,14 @@
[flake8]
max-line-length = 99

max-line-length = 99,
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 think we need the comma at the end (and not sure if it can cause problems)

setup.cfg Outdated
max-line-length = 99

max-line-length = 99,
exclude = setup.py,asv/commands,asv/extern,asv/plugins,asv/template/benchmarks,
Copy link
Member

Choose a reason for hiding this comment

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

This looks great, thanks.

Only thing I'd do, is to have one file per line. It looks better the way you did it, as it's not super long, but with one line per file PRs will be easier to review when we keep fixing the pending files. And also, conflicts will be easier to solve, if files are fixed in parallel.

Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Feb 10, 2022

Choose a reason for hiding this comment

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

Yes, I agree. Let me incorporate all the changes

@dorothykiz1
Copy link
Contributor Author

@datapythonista this PR is ready for your review

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.

Thanks @dorothykiz1, couple of details, but almost there.

@@ -13,7 +13,4 @@ jobs:
run: pip install flake8

- name: flake8 all repo only show erros
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 the name I was referring to, it can be just left as just flake8 (it's not true anymore after you remove the || true that we only show errors, we also fail the CI if they exist).


- name: flake8 validating correct file(s)
run: flake8 asv/main.py asv/repo.py asv/results.py asv/runner.py asv/statistics.py asv/step_detect.py asv/util.py test/benchmark/ asv/__init__.py asv/benchmarks.py asv/config.py asv/benchmark.py
run: flake8 . # preventing CI failing while flake8 issues exist
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the comment too, as we're not preventing the CI from failing anymore now.

setup.cfg Outdated
asv/machine.py,
asv/graph.py,
asv/.pytest_cache/d/asv-wheels/cache/tmp
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a temporary file, and I don't think it'll exist in the CI. Can you remove it, and see if the build is still green? I think it should.

Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Feb 10, 2022

Choose a reason for hiding this comment

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

Thanks, @datapythonista however these temp files had some flake 8 errors ,that's why I had included their folder,kindly advise

./.pytest_cache/d/asv-wheels/cache/tmp/asv_dummy_test_package_2-0.3.9/asv_dummy_test_package_2/init.py:1:22: W292 no newline at end of file
./.pytest_cache/d/asv-wheels/cache/tmp/asv_dummy_test_package_1-0.14/asv_dummy_test_package_1/init.py:1:21: W292 no newline at end of file
./.pytest_cache/d/asv-wheels/cache/tmp/asv_dummy_test_package_2-0.3.7/asv_dummy_test_package_2/init.py:1:22: W292 no newline at end of file

Copy link
Member

Choose a reason for hiding this comment

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

Is this happening in the CI or locally? I think the CI shouldn't fail, but maybe a good idea anyway to ignore anything in .pytest_cache directories, since those are temporary. Not sure exactly how to ignore all directories with that name, but I'm sure you'll find out.

setup.cfg Outdated
benchmarks/step_detect.py,
benchmarks/__init__.py,
.pytest_cache/d/asv-wheels/cache/tmp,
Copy link
Member

Choose a reason for hiding this comment

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

Another temporary file, same as the previous.

setup.cfg Outdated
benchmarks/__init__.py,
.pytest_cache/d/asv-wheels/cache/tmp,
docs/source
Copy link
Member

Choose a reason for hiding this comment

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

I think there is just one Python file in this directory, no big deal, but probably worth having the file here, and not the whole dir (so people who wants to work in any of these know that it's just one file, and doesn't feel intimidated thinking it's lots of things in that dir).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, i can add this .this makes sense let me pick the exact files.

@dorothykiz1
Copy link
Contributor Author

@datapythonista this PR is ready for your review

@datapythonista
Copy link
Member

@datapythonista this PR is ready for your review

Did you push your changes? I don't think there is any update since the last review.

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.

Thanks @dorothykiz1 looks perfect, I'll merge on green

@dorothykiz1
Copy link
Contributor Author

Sure,Thank you @datapythonista

@datapythonista datapythonista merged commit 13eb401 into airspeed-velocity:master Feb 10, 2022
@datapythonista
Copy link
Member

Thanks @dorothykiz1, really nice

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