mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	 3ccec68a05
			
		
	
	
		3ccec68a05
		
	
	
	
	
		
			
			- Specialcase extended slices that amount to a shallow copy the same way as is done for simple slices, in the tuple, string and unicode case. - Specialcase step-1 extended slices to optimize the common case for all involved types. - For lists, allow extended slice assignment of differing lengths as long as the step is 1. (Previously, 'l[:2:1] = []' failed even though 'l[:2] = []' and 'l[:2:None] = []' do not.) - Implement extended slicing for buffer, array, structseq, mmap and UserString.UserString. - Implement slice-object support (but not non-step-1 slice assignment) for UserString.MutableString. - Add tests for all new functionality.
		
			
				
	
	
		
			29 lines
		
	
	
	
		
			789 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			789 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Unit tests for buffer objects.
 | |
| 
 | |
| For now, tests just new or changed functionality.
 | |
| 
 | |
| """
 | |
| 
 | |
| import unittest
 | |
| from test import test_support
 | |
| 
 | |
| class BufferTests(unittest.TestCase):
 | |
| 
 | |
|     def test_extended_getslice(self):
 | |
|         # Test extended slicing by comparing with list slicing.
 | |
|         s = "".join(chr(c) for c in list(range(255, -1, -1)))
 | |
|         b = buffer(s)
 | |
|         indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
 | |
|         for start in indices:
 | |
|             for stop in indices:
 | |
|                 # Skip step 0 (invalid)
 | |
|                 for step in indices[1:]:
 | |
|                     self.assertEqual(b[start:stop:step],
 | |
|                                      s[start:stop:step])
 | |
| 
 | |
| 
 | |
| def test_main():
 | |
|     test_support.run_unittest(BufferTests)
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     test_main()
 |