diff options
author | Eli Bendersky <eliben@gmail.com> | 2011-02-25 05:47:53 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2011-02-25 05:47:53 (GMT) |
commit | cbbaa96036b8467c21f2c7127a3711fcb405d00f (patch) | |
tree | eb49c673b4b8adb17eb3bf17188c65df9d5f89ea /Lib/test/list_tests.py | |
parent | 3108f983197991865c30d49de37b9a48e60c656e (diff) | |
download | cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.zip cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.tar.gz cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.tar.bz2 |
Issue #10516: adding list.clear() and list.copy() methods
Diffstat (limited to 'Lib/test/list_tests.py')
-rw-r--r-- | Lib/test/list_tests.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index e3a7845..89ea40f 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -425,6 +425,48 @@ class CommonTest(seq_tests.CommonTest): self.assertRaises(TypeError, u.reverse, 42) + def test_clear(self): + u = self.type2test([2, 3, 4]) + u.clear() + self.assertEqual(u, []) + + u = self.type2test([]) + u.clear() + self.assertEqual(u, []) + + u = self.type2test([]) + u.append(1) + u.clear() + u.append(2) + self.assertEqual(u, [2]) + + self.assertRaises(TypeError, u.clear, None) + + def test_copy(self): + u = self.type2test([1, 2, 3]) + v = u.copy() + self.assertEqual(v, [1, 2, 3]) + + u = self.type2test([]) + v = u.copy() + self.assertEqual(v, []) + + # test that it's indeed a copy and not a reference + u = self.type2test(['a', 'b']) + v = u.copy() + v.append('i') + self.assertEqual(u, ['a', 'b']) + self.assertEqual(v, u + ['i']) + + # test that it's a shallow, not a deep copy + u = self.type2test([1, 2, [3, 4], 5]) + v = u.copy() + v[2].append(666) + self.assertEqual(u, [1, 2, [3, 4, 666], 5]) + self.assertEqual(u, v) + + self.assertRaises(TypeError, u.copy, None) + def test_sort(self): u = self.type2test([1, 0]) u.sort() |