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

ElmLintBear: Remove pragma: no cover #1997

Merged
merged 1 commit into from Aug 15, 2017
Merged

Conversation

yash-nisar
Copy link
Member

@yash-nisar yash-nisar commented Aug 14, 2017

Remove pragma: no cover in check_prerequisites by adding
a suitable test.

Closes #1996
Related to #1618

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

@yash-nisar
Copy link
Member Author

CC @jayvdb @Makman2

def test_check_prerequisites(self):
_shutil_which = shutil.which
try:
shutil.which = lambda *args, **kwargs: None
Copy link
Member

Choose a reason for hiding this comment

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

use @patch on the test method. You can patch the which you imported from shutil, so the patch-module-string gets bears.elm.ElmLintBear.which. Then you don't need to change the import inside ElmLintBear, you just have to remove the pragma.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, on it. 👍

@@ -1,4 +1,6 @@
import shutil
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file contains unused source code.

PyUnusedCodeBear, severity NORMAL, section flakes.

The issue can be fixed by applying the following patch:

--- a/tests/elm/ElmLintBearTest.py
+++ b/tests/elm/ElmLintBearTest.py
@@ -1,4 +1,3 @@
-import shutil
 from queue import Queue
 from unittest.mock import patch
 

@yash-nisar
Copy link
Member Author

Done @Makman2

@Nosferatul
Copy link
Member

I think this pr is ready, what do you say @Makman2 ?

@Makman2
Copy link
Member

Makman2 commented Aug 14, 2017

yes looks good :)

@Makman2
Copy link
Member

Makman2 commented Aug 14, 2017

ack 9d2563a

@yash-nisar
Copy link
Member Author

reack b1e3fbd

Remove `pragma: no cover` in `check_prerequisites` by adding
a suitable test.

Closes coala#1996
Related to coala#1618
@yash-nisar
Copy link
Member Author

yash-nisar commented Aug 15, 2017

I'm doing a minor change -> Replacing assertTrue with assertEqual as in the python docs.

This method should also be avoided when more specific methods are available (e.g. assertEqual(a, b) instead of assertTrue(a == b)), because they provide a better error message in case of failure.

@yash-nisar
Copy link
Member Author

ack 0a25352

@yukiisbored
Copy link
Member

@rultor please merge

@rultor
Copy link

rultor commented Aug 15, 2017

@rultor please merge

@yukiisbored OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 0a25352 into coala:master Aug 15, 2017
@rultor
Copy link

rultor commented Aug 15, 2017

@rultor please merge

@yukiisbored Done! FYI, the full log is here (took me 2min)

@yash-nisar yash-nisar deleted the elm-pragma branch August 15, 2017 05:31
@yash-nisar
Copy link
Member Author

Thanks @yukiisbored 😄

@Makman2
Copy link
Member

Makman2 commented Aug 15, 2017

I'm doing a minor change -> Replacing assertTrue with assertEqual as in the python docs.

This method should also be avoided when more specific methods are available (e.g. assertEqual(a, b) instead of assertTrue(a == b)), because they provide a better error message in case of failure.

Actually the docs want you to avoid such operators like == to use in assertTrue. If your result should be true in the end, assertTrue is just effective^^ however like this is also okay^^

@Makman2
Copy link
Member

Makman2 commented Aug 15, 2017

But if you do a change, don't ack it yourself, it has to be reviewed again by someone else.

@yash-nisar
Copy link
Member Author

Sure, will keep that in mind. I felt the need to change it because I missed a bug in my travis PR. Also, I've opened an issue with regard to this that will avoid future bugs 😉 :

In general, self.assertTrue('some_string') does not fail. So even if check_prerequisites() returns 'You are not connected to the internet.', the test will pass.
This can be avoided either by explicitly doing self.assertTrue(URLBear.check_prerequisites() == True) or by self.assertEqual(URLBear.check_prerequisites(), True). The latter one is more preferred.

@Makman2
Copy link
Member

Makman2 commented Aug 15, 2017

Actually the docs want you to avoid such operators like == to use in assertTrue. If your result should be true in the end, assertTrue is just effective^^ however like this is also okay^^

Nvm this, assertEqual(x, True) and assertTrue(x) are two different things. assertTrue invokes bool on the given expression, while assertEqual does not.

@yash-nisar
Copy link
Member Author

yash-nisar commented Aug 15, 2017

Yeah, I agree 👍 . Just wanted to make sure things like these -> self.assertTrue('some_string') do not pass and are taken care of. 😉

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

Successfully merging this pull request may close these issues.

Remove pragma: no cover from ElmLintBear
6 participants