Walter Dörwald | 1dde95d | 2003-12-08 11:38:45 +0000 | [diff] [blame] | 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 | |
Raymond Hettinger | bcab2b2 | 2004-09-29 08:03:17 +0000 | [diff] [blame] | 21 | def test_main(verbose=None): |
Walter Dörwald | 1dde95d | 2003-12-08 11:38:45 +0000 | [diff] [blame] | 22 | test_support.run_unittest(ListTest) |
| 23 | |
Raymond Hettinger | bcab2b2 | 2004-09-29 08:03:17 +0000 | [diff] [blame] | 24 | # verify reference counting |
| 25 | import sys |
| 26 | if verbose and hasattr(sys, "gettotalrefcount"): |
| 27 | import gc |
| 28 | counts = [None] * 5 |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame^] | 29 | for i in range(len(counts)): |
Raymond Hettinger | bcab2b2 | 2004-09-29 08:03:17 +0000 | [diff] [blame] | 30 | test_support.run_unittest(ListTest) |
| 31 | gc.collect() |
| 32 | counts[i] = sys.gettotalrefcount() |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 33 | print(counts) |
Raymond Hettinger | bcab2b2 | 2004-09-29 08:03:17 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | if __name__ == "__main__": |
| 37 | test_main(verbose=True) |