mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #10516: added copy() and clear() methods to bytearrays as well
This commit is contained in:
		
							parent
							
								
									91221f2857
								
							
						
					
					
						commit
						4db28d3343
					
				
					 4 changed files with 63 additions and 5 deletions
				
			
		|  | @ -564,6 +564,39 @@ def test_reverse(self): | |||
|         b.reverse() | ||||
|         self.assertFalse(b) | ||||
| 
 | ||||
|     def test_clear(self): | ||||
|         b = bytearray(b'python') | ||||
|         b.clear() | ||||
|         self.assertEqual(b, b'') | ||||
| 
 | ||||
|         b = bytearray(b'') | ||||
|         b.clear() | ||||
|         self.assertEqual(b, b'') | ||||
| 
 | ||||
|         b = bytearray(b'') | ||||
|         b.append(ord('r')) | ||||
|         b.clear() | ||||
|         b.append(ord('p')) | ||||
|         self.assertEqual(b, b'p') | ||||
| 
 | ||||
|     def test_copy(self): | ||||
|         b = bytearray(b'abc') | ||||
|         bb = b.copy() | ||||
|         self.assertEqual(bb, b'abc') | ||||
| 
 | ||||
|         b = bytearray(b'') | ||||
|         bb = b.copy() | ||||
|         self.assertEqual(bb, b'') | ||||
| 
 | ||||
|         # test that it's indeed a copy and not a reference | ||||
|         b = bytearray(b'abc') | ||||
|         bb = b.copy() | ||||
|         self.assertEqual(b, bb) | ||||
|         self.assertIsNot(b, bb) | ||||
|         bb.append(ord('d')) | ||||
|         self.assertEqual(bb, b'abcd') | ||||
|         self.assertEqual(b, b'abc') | ||||
| 
 | ||||
|     def test_regexps(self): | ||||
|         def by(s): | ||||
|             return bytearray(map(ord, s)) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Eli Bendersky
						Eli Bendersky