-
Notifications
You must be signed in to change notification settings - Fork 278
Start linting tests with black, isort and mypy and exclude old test files #1624
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
Conversation
Pull Request Test Coverage Report for Build 1381758103Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
For context, I am planning to add this list of excluded files in
which is ugly, but it's not complicated to understand and it works. |
ca91fef
to
b86a31c
Compare
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 think doing all the linters at once is the correct choice (so we get to see the whole configuration at once) but instead of including changes in 8 test files maybe one representative file would be a good start -- the patch becomes quite big?
Mostly it looks good though. There seem to be quite a few pylint disables in the code: I can understand some of them (e.g. test data is longer than line length) but not really others. I saw at least these that seemed like they should be fixed:
- invalid-name: let's fix the variable names or lets change the pylint config to accept "_" as dummy variable: adding individual disables in the code is just spam).
- consider-iterating-dictionary
- redefined-builtin
- no-self-use
With regards to how we choose what to lint: four different almost identical lists in three different files is not great... maybe it's not the end of he world but let's keep an open mind on the possibility of moving files as well.
@@ -174,6 +184,7 @@ def publish_root(self): | |||
logger.debug("Published root v%d", self.root.version) | |||
|
|||
def fetch(self, url: str) -> Iterator[bytes]: | |||
"""Fetches data from the given url and yeilds an Iterator""" |
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.
returns an Iterator (or yields bytes).
@lukpueh I forget, have we discussed dummy-variables-rgx in pylintrc at some point? I rather like using It's not a big deal though: if this is a conscious decision then let's just rename the variables -- there's just one or two anyway |
@jku, I don't think we have. Does pylint choke on FYI, it seems like in the past |
I can do that, but also some of the cases and disabled errors of the tests won't be seen that way.
I tried to make sensible decisions for that, but each of the disabled errors should be examined individually.
Yea, I know it's not beautiful. The problem is each of the test files has it's own format for excluding multiple files. I will do some research on those items later today. |
Looking at how different the formats are, this will probably get difficult and ugly very quickly.
that would be better than multiple files (still not great but a lot better) |
Hmm, you have a point, I'm not sure what the issue is exactly. I do remember stumbling on this before and based on the patch Martin did now as well: @MVrachev if you can figure out which rule forced you to use |
b6bddd4
to
04b32f6
Compare
@jku I have good news: I was able to move both
I didn't add it here as we had discussed that After reading different issues It seems as after PEP 518 many projects opt-in using So, @jku what do you think? PS: I had to force-push so many times as I was not able to reproduce a |
Currently, we are using 4 tools: black, pylint, isort and mypy. We want to run all 4 of them on our tests for the new codebase to make it more readable and maintainable, but we don't want to run it on the old test files as they are following the old style guidelines. In order to achieve that we want to use an exclusion list instead of an inclusion list as the new code base will be developed in the future and new test files will appear. On another hand, we don't expect any more additional test files against the old code, so this list is static. I decided to hardcode the names we want to exclude because that way we won't have to remove the Git history, as opposed to renaming or moving the old test files. Even though the list is big, around 30 files, I think this solution is fine as this list will only contain files testing the old code meaning the list will have static content. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
All of the changes included are a result of applying black on our tests on the new code. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Currently, we are using 4 tools: black, pylint, isort and mypy. We want to run all 4 of them on our tests for the new codebase to make it more readable and maintainable, but we don't want to run it on the old test files as they are following the old style guidelines. I am using the same approach as the one used for black - create an exclusion list from old test files we want to ignore. I didn't used moved or renamed the old test files as that will remove the Git history. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
All of the changes included are a result of applying isort on our tests on the new code. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Currently, we are using 4 tools: black, pylint, isort and mypy. We want to run all 4 of them on our tests for the new codebase to make it more readable and maintainable, but we don't want to run it on the old test files as they are following the old style guidelines. I am using the same approach as the one used for black - create an exclusion list from old test files we want to ignore. I didn't used moved or renamed the old test files as that will remove the Git history. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Pylint reported a couple of warnings flagged as "duplicate-code". We were truly duplicating code - one of the examples was when we imported the same objects from tuf/api/metadata.py: MetaFile, Role, Root, Snapshot, TargetFile, Targets, and Timestamp in two separate modules. So, I thought we do want to be repetitive here and include that code at both modules. The problem is that besides importing the above classes the modules imported other classes from tuf.api.metadata.py and there was no way to disable this check. I searched and found out that this is a known problem: pylint-dev/pylint#214. That's why the only solution I see is to disable this warning temporarily and hoping that one day when this issue is fixed we will remember to turn it on again. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Disable pylint line-too-long warning as test_metadata_serialization.py is a special case where having longer lines helps the readibility of the test cases data. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Address or disable pylint warnings raised on all test files inside tests/ testing the code of the new implementation. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
_ is often used when a function returns multiple values and you need a sub-portion of them. Then, those values that are unnecessary can be named _. Currently, pylint warns us that this is not a good variable name, so fix that. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Move configuration for pylint linting tool over the refactored code in pyproject.toml. This is done in order to have one unified place where we will have the 30+ lines exclusion list of old test files we don't want to lint. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Move configuration for mypy linting tool over the refactored code in pyproject.toml. This is done in order to have one unified place where we will have the 30+ lines exclusion list of old test files we don't want to lint. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
04b32f6
to
17fdcbe
Compare
It was not easy, but I think I resolved all of the conflicts. |
I noticed the CI run 19 tests here, but for #1636 it runs 20. |
If you mean e.g. that I could go through all of the Actual issues in the code that you find could be fixed with separate PRs (that would get handled before this PR) or as part of this one -- the former approach will make them faster to merge. In fact even the code fixes already in this PR could easily be made in separate smaller PRs: we'd fix the issues first, and then enabling the new config would be easier to review as it would only include the config changes plus the required |
I think I have used disables only for the places I find appropriate.
I will do that on Monday and create new prs about the code changes that make sense from the linters and leave the disables and config changes in separate pr. |
This pr will be replaced with a couple of other prs. Closing this pr. |
Addresses #1582
There will be another pr for mypy.
Description of the changes being introduced by the pull request:
Currently, we are using 4 tools:
black
,pylint
,isort
andmypy
.We want to run all 4 of them on our tests for the new codebase to make
it more readable and maintainable, but we don't want to run it on the
old test files as they are following the old style guidelines.
In order to achieve that we want to use an exclusion list instead of
an inclusion list as the new code base will be developed in the future
and new test files will appear. On another hand, we don't expect any
more additional test files against the old code, so this list is static.
I decided to hardcode the names we want to exclude because that way we
won't have to remove the Git history, as opposed to renaming or moving
the old test files.
Even though the list is big, around 30 files, I think this solution is
fine as this list will only contain files testing the old code meaning
the list will have static content.
Signed-off-by: Martin Vrachev mvrachev@vmware.com
Please verify and check that the pull request fulfills the following
requirements: