Skip to content

Fix use of assert #2015

Closed
Closed

Description

@peterjc

I'm logging this as a good first issue ideal for a new contributor (but if you are the maintainer of any of the files listed here, feel free to fix them yourself). If you want to work on this, I suggest commenting first saying something like "I'll work on Bio/SwissProt to start with" in order to avoid duplicated effort.

If you use the code checking tool flake8 with the bugbear plugin, it finds a number of issues with our code - specifically we have a modest number of assert statements which should ideally be replaced.

You can install the tools as follows:

$ pip install --upgrade flake8 flake8-bugbear

Run flake8 to look for this problem specifically:

$ flake8 --isolated --select B011 Bio/ Tests/
Bio/SwissProt/__init__.py:354:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Bio/SwissProt/__init__.py:396:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Bio/SeqIO/PirIO.py:185:5: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Bio/SeqIO/QualityIO.py:1372:5: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Bio/AlignIO/EmbossIO.py:61:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Bio/AlignIO/EmbossIO.py:207:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_Nexus.py:687:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_SffIO.py:564:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/seq_tests_common.py:142:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:328:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:356:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:367:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:406:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:428:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/common_BioSQL.py:701:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_GenomeDiagram.py:695:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_GenomeDiagram.py:702:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_Fasttree_tool.py:82:5: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_Fasttree_tool.py:102:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_Fasttree_tool.py:114:5: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_SeqIO.py:636:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_SeqIO.py:690:17: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_SeqIO_convert.py:66:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_SeqIO_convert.py:76:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_AlignIO.py:227:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_AlignIO.py:254:9: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
Tests/test_AlignIO.py:332:13: B011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().

In the Tests/ cases, within a unittest based class they should probably use self.assertTrue(...) instead.

Otherwise, and in the Bio/ cases, they should probably be reworked to an if-statement raising a ValueError or similar.

See also #1515 which looked at multi-line assert statements which failed other flake8 style rules, and has some relevant discussion and examples.

Activity

  1. added
    good first issue
    on Apr 18, 2019
  2. peterjc commented on Apr 18, 2019

    @peterjc
    MemberAuthor

    See also 4cf0c19 which added B011 and a few other issues flagged by flake8-bugbear to our default ignore lists.

    Once all the B011 cases are fixed, we can remove these from the ignore list - and perhaps start usingflake8-bugbear as part of the automated testing too.

  3. benjaminr commented on Apr 21, 2019

    @benjaminr
    Contributor

    Happy to look at resolving all of these.

  4. peterjc commented on Apr 22, 2019

    @peterjc
    MemberAuthor

    Turned out there was a configuration error meaning TravisCI was not testing with flake8-bugbear, fix in hand #2025

  5. added a commit that references this issue on Apr 22, 2019
  6. peterjc commented on Apr 22, 2019

    @peterjc
    MemberAuthor

    All done, thank you!

  7. benjaminr commented on Apr 22, 2019

    @benjaminr
    Contributor

    All done, thank you!

    No problem!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    StyleTestinggood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions