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

Useful new lint ideas #477

Open
wmanley opened this issue Dec 22, 2017 · 2 comments
Open

Useful new lint ideas #477

wmanley opened this issue Dec 22, 2017 · 2 comments

Comments

@wmanley
Copy link
Contributor

wmanley commented Dec 22, 2017

Some ideas for lints inspired by code seen in the wild:

assert-true-has-no-effect

assert True

assert True statement has no effect. Remove this line or replace it with pass

assert True, "Things are fine"

assert True statement has no effect. Perhaps you meant logging.info("Things are fine")

assert-unnecessary-if

if stbt.match('abcd.png'):
    ...
else:
    assert False, "Didn't find abcd menu"

Unnecessary if statement. Consider rewriting with assert: assert stbt.match('abcd.png'), "Didn't find abcd menu"

But this code is fine:

if stbt.match('abcd.png'):
    ...
elif stbt.match('efgh.png'):
    ...
else:
    assert False, "Couldn't find menu"

return-unnecessary-if

This one is possibly more contentious:

if stbt.match('abcd.png'):
    return True
else:
    return False

This is preferred:

return bool(stbt.match('abcd.png'))
@drothlis
Copy link
Contributor

slow-is-visible

Does is_visible use stbt.match_text or stbt.ocr as its first operation? You can often discard 90% of false-positives by doing a fast match operation first, for example:

return (stbt.match("image-that-is-present-in-this-and-some-other-screens.png") and 
        stbt.match_text("text that is only present in this screen"))

@wmanley
Copy link
Contributor Author

wmanley commented Sep 20, 2018

Public FrameObject property returns MatchResult object

...or possibly another object that has a .frame member?

class Example(stbt.FrameObject):
    @property
    def is_good(self):
        return stbt.match("good.png")

Either explicitly make it a bool()

class Example(stbt.FrameObject):
    @property
    def is_good(self):
        return bool(stbt.match("good.png"))

or make the property private:

class Example(stbt.FrameObject):
    @property
    def _is_good(self):
        return stbt.match("good.png")

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

No branches or pull requests

2 participants