| 
									
										
										
										
											2008-05-08 14:29:10 +00:00
										 |  |  | from unittest import TestCase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | import textwrap | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestIndent(TestCase): | 
					
						
							|  |  |  |     def test_indent(self): | 
					
						
							|  |  |  |         h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth', | 
					
						
							|  |  |  |              {'nifty': 87}, {'field': 'yes', 'morefield': False} ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect = textwrap.dedent("""\
 | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-10-31 08:00:16 +00:00
										 |  |  |         \t[ | 
					
						
							|  |  |  |         \t\t"blorpie" | 
					
						
							|  |  |  |         \t], | 
					
						
							|  |  |  |         \t[ | 
					
						
							|  |  |  |         \t\t"whoops" | 
					
						
							|  |  |  |         \t], | 
					
						
							|  |  |  |         \t[], | 
					
						
							|  |  |  |         \t"d-shtaeou", | 
					
						
							|  |  |  |         \t"d-nthiouh", | 
					
						
							|  |  |  |         \t"i-vhbjkhnth", | 
					
						
							|  |  |  |         \t{ | 
					
						
							|  |  |  |         \t\t"nifty": 87 | 
					
						
							|  |  |  |         \t}, | 
					
						
							|  |  |  |         \t{ | 
					
						
							|  |  |  |         \t\t"field": "yes", | 
					
						
							|  |  |  |         \t\t"morefield": false | 
					
						
							|  |  |  |         \t} | 
					
						
							| 
									
										
										
										
											2008-05-08 14:29:10 +00:00
										 |  |  |         ]""")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d1 = json.dumps(h) | 
					
						
							|  |  |  |         d2 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': ')) | 
					
						
							| 
									
										
										
										
											2010-10-31 08:00:16 +00:00
										 |  |  |         d3 = json.dumps(h, indent='\t', sort_keys=True, separators=(',', ': ')) | 
					
						
							| 
									
										
										
										
											2008-05-08 14:29:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         h1 = json.loads(d1) | 
					
						
							|  |  |  |         h2 = json.loads(d2) | 
					
						
							| 
									
										
										
										
											2010-10-31 08:00:16 +00:00
										 |  |  |         h3 = json.loads(d3) | 
					
						
							| 
									
										
										
										
											2008-05-08 14:29:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.assertEquals(h1, h) | 
					
						
							|  |  |  |         self.assertEquals(h2, h) | 
					
						
							| 
									
										
										
										
											2010-10-31 08:00:16 +00:00
										 |  |  |         self.assertEquals(h3, h) | 
					
						
							|  |  |  |         self.assertEquals(d2, expect.expandtabs(2)) | 
					
						
							|  |  |  |         self.assertEquals(d3, expect) |