| 1 | import unittest |
| 2 | from test import test_support, list_tests |
| 3 | |
| 4 | class ListTest(list_tests.CommonTest): |
| 5 | type2test = list |
| 6 | |
| 7 | def test_truth(self): |
| 8 | super(ListTest, self).test_truth() |
| 9 | self.assert_(not []) |
| 10 | self.assert_([42]) |
| 11 | |
| 12 | def test_identity(self): |
| 13 | self.assert_([] is not []) |
| 14 | |
| 15 | def test_len(self): |
| 16 | super(ListTest, self).test_len() |
| 17 | self.assertEqual(len([]), 0) |
| 18 | self.assertEqual(len([0]), 1) |
| 19 | self.assertEqual(len([0, 1, 2]), 3) |
| 20 | |
| 21 | def test_main(verbose=None): |
| 22 | test_support.run_unittest(ListTest) |
| 23 | |
| 24 | # verify reference counting |
| 25 | import sys |
| 26 | if verbose and hasattr(sys, "gettotalrefcount"): |
| 27 | import gc |
| 28 | counts = [None] * 5 |
| 29 | for i in xrange(len(counts)): |
| 30 | test_support.run_unittest(ListTest) |
| 31 | gc.collect() |
| 32 | counts[i] = sys.gettotalrefcount() |
| 33 | print counts |
| 34 | |
| 35 | |
| 36 | if __name__ == "__main__": |
| 37 | test_main(verbose=True) |