mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	gh-114894: add array.array.clear() method (#114919)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
		
							parent
							
								
									5319c66550
								
							
						
					
					
						commit
						9d1a353230
					
				
					 7 changed files with 71 additions and 1 deletions
				
			
		|  | @ -1014,6 +1014,29 @@ def test_pop(self): | |||
|             array.array(self.typecode, self.example[3:]+self.example[:-1]) | ||||
|         ) | ||||
| 
 | ||||
|     def test_clear(self): | ||||
|         a = array.array(self.typecode, self.example) | ||||
|         with self.assertRaises(TypeError): | ||||
|             a.clear(42) | ||||
|         a.clear() | ||||
|         self.assertEqual(len(a), 0) | ||||
|         self.assertEqual(a.typecode, self.typecode) | ||||
| 
 | ||||
|         a = array.array(self.typecode) | ||||
|         a.clear() | ||||
|         self.assertEqual(len(a), 0) | ||||
|         self.assertEqual(a.typecode, self.typecode) | ||||
| 
 | ||||
|         a = array.array(self.typecode, self.example) | ||||
|         a.clear() | ||||
|         a.append(self.example[2]) | ||||
|         a.append(self.example[3]) | ||||
|         self.assertEqual(a, array.array(self.typecode, self.example[2:4])) | ||||
| 
 | ||||
|         with memoryview(a): | ||||
|             with self.assertRaises(BufferError): | ||||
|                 a.clear() | ||||
| 
 | ||||
|     def test_reverse(self): | ||||
|         a = array.array(self.typecode, self.example) | ||||
|         self.assertRaises(TypeError, a.reverse, 42) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mike Zimin
						Mike Zimin