Repository navigation
Description
We have now dropped Python 2 support, which means we can take advantage of many of the unittest framework methods where were not present on Python 2.
This issue is specifically for using assertIn and assertNotIn, both new in Python 3.1:
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIn
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNotIn
Example noted on #2694,
self.assertFalse(None in p1, "Bad input values for %s: %r" % (prop_name, p1))becomes:
self.assertNotIn(None, p1, "Bad input values for %s: %r" % (prop_name, p1))A quick grep finds a dozen easy cases which should use assertNotIn, there could be more - especially multiline statements:
$ grep assertFalse test_*.py | grep " in "
test_Crystal.py: self.assertFalse("ser" in chain)
test_Crystal.py: self.assertFalse("b" in target.data)
test_Crystal.py: self.assertFalse("z" in self.crystal)
test_GenBank.py: self.assertFalse("structured_comment" in record.annotations)
test_Phylo_CDAO.py: self.assertFalse(None in p1, "Bad input values for %s: %r" % (prop_name, p1))
test_Phylo_CDAO.py: self.assertFalse(None in p2, "Bad output values for %s: %r" % (prop_name, p2))
test_SearchIO_model.py: self.assertFalse("hit5" in self.qresult)
test_SearchIO_model.py: self.assertFalse(hit41 in self.qresult)
test_samtools_tool.py: self.assertFalse("[bam_pileup_core]" in stdout)
test_samtools_tool.py: self.assertFalse("[bam_pileup_core]" in stdout)
test_seq.py: self.assertFalse("-" in ambiguous_dna_values)
test_seq.py: self.assertFalse("?" in ambiguous_dna_values)
There are about three times as many candidates using this search:
$ grep assertTrue test_*.py | grep " in "
test_BWA_tool.py: self.assertTrue("Finished constructing BWT" in str(stdout) + str(stderr),
test_BWA_tool.py: self.assertTrue("fail to locate the index" not in str(stderr) + str(stdout),
...
Note that first example would be assertIn while the second example used not in and becomes assertNotIn instead.
Activity
Implements assert changes as detailed in biopython #2698
peterjc commentedon Feb 29, 2020
Closed via #2772, thank you @adcrn