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

bears/general: Add FileModeBear #2912

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bkhanale
Copy link
Member

@bkhanale bkhanale commented Jun 4, 2019

Closes #2370

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!

Copy link
Member

@abhishalya abhishalya left a comment

Choose a reason for hiding this comment

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

Overall looks good 👍


def test_x_to_x_permissions(self):
os.chmod(FILE_PATH, stat.S_IXUSR)
if platform.system() != 'Windows':
Copy link
Member

Choose a reason for hiding this comment

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

Mention the reason wherever you have done this.

Copy link
Member

Choose a reason for hiding this comment

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

No. Get rid of it. If this bear doesnt support Windows, that fact shouldnt be hidden inside the logic of the tests.

A .coafile is a cross-platform specification, and it must not cause failures on only one platform.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps create a separate test class for executable permissions, and the class should be skipped on Windows for tests which dont work on Windows, and potentially we need a second extra test class which does Windows specific testing to show that specifying executable bits in the .coafile results in a mild note in the coala log, but does not cause it to fail.

@bkhanale bkhanale force-pushed the filemodebear branch 2 times, most recently from 70a08d9 to b9b0d97 Compare July 21, 2019 10:25
Copy link
Member

@abhishalya abhishalya left a comment

Choose a reason for hiding this comment

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

Few improvements, other things look good.

bears/general/FileModeBear.py Outdated Show resolved Hide resolved
bears/general/FileModeBear.py Outdated Show resolved Hide resolved
bears/general/FileModeBear.py Outdated Show resolved Hide resolved
tests/general/FileModeBearTest.py Outdated Show resolved Hide resolved
@bkhanale bkhanale force-pushed the filemodebear branch 2 times, most recently from 84ec0de to 1a12c51 Compare July 22, 2019 04:45
@jayvdb
Copy link
Member

jayvdb commented Jul 22, 2019

Current codecov failure at 99.91% can be ignored - https://travis-ci.org/coala/coala-bears/jobs/561920971 shows the new bear is getting 100% test coverage


def test_x_to_x_permissions(self):
os.chmod(FILE_PATH, stat.S_IXUSR)
if platform.system() != 'Windows':
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps create a separate test class for executable permissions, and the class should be skipped on Windows for tests which dont work on Windows, and potentially we need a second extra test class which does Windows specific testing to show that specifying executable bits in the .coafile results in a mild note in the coala log, but does not cause it to fail.

@jayvdb
Copy link
Member

jayvdb commented Aug 22, 2019

It should be possible to get executable bit working correctly on Windows, and this PR cant close the issue without executable support, as executable support is the primary motivation for this bear, and the need to include Windows was a consistent message throughout the comments of the issue.

@bkhanale
Copy link
Member Author

@jayvdb The bear works fine for Windows (as it only reads the file permissions and doesn't change them), the problem was I couldn't test it properly on Windows since Python can only set read-only flags on it. One way to test this could be to rename the file to the extension .exe which automatically sets the executable flag.



FILE_PATH = os.path.join(os.path.dirname(__file__),
'filemode_test_files', 'test_file.txt')
Copy link
Member

Choose a reason for hiding this comment

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

the issue asked for "...on scripts" . Why are you using .txt ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess having no extension at all would've been better. This is because the bear is supposed to check for all file permissions as mentioned here and is not just restricted scripts.

Copy link
Member

@jayvdb jayvdb Aug 22, 2019

Choose a reason for hiding this comment

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

Start with the realistic scenario of scripts having .sh / .bash etc extensions and make sure you can get that working and tested properly, before trying extensionless voodoo.

@jayvdb
Copy link
Member

jayvdb commented Aug 22, 2019

@bkhanale ,

... the problem was I couldn't test it properly on Windows

If you can not test it, you have no way to determine that is works, and you should not attempt to argue that it does work.

I can see a mile away it does not achieve what the issue requested.

No you do not get to create a useless test by renaming files to .exe . That isnt what the issue asked for.

And even ignoring the fact the bear doesnt work, the test method test_x_to_x_permissions on Windows does:

os.chmod(FILE_PATH, stat.S_IXUSR)
os.chmod(FILE_PATH, stat.S_IRUSR)

That is not a test of the bear, it it. That is wrong. Fix it.

https://github.com/coala/coala-bears/pull/2912/files#r294035442 asked you two months ago to document why you were doing that. You havent done that. Why not?

Why are you using custom test logic instead of verify_local_bear? Is there something about this bear which means verify_local_bear doesnt work for any of the tests? If so, why not use self.check_invalidity?

@abhishalya
Copy link
Member

And even ignoring the fact the bear doesnt work, the test method test_x_to_x_permissions on Windows does:

I guess that he did to roll back changes made to the file permissions (which I guess defaults to read permission).

Why are you using custom test logic instead of verify_local_bear? Is there something about this bear which means verify_local_bear doesnt work for any of the tests? If so, why not use self.check_invalidity?

Yep, you can use check_validity wherever you're not checking for the message statements.

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.

Create FileModeBear
3 participants