@@ -828,6 +828,7 @@ def test_indent(self):
828
828
b'</html>'
829
829
)
830
830
831
+ def test_indent_space (self ):
831
832
elem = ET .XML ("<html><body><p>pre<br/>post</p><p>text</p></body></html>" )
832
833
ET .indent (elem , space = '\t ' )
833
834
self .assertEqual (
@@ -840,6 +841,18 @@ def test_indent(self):
840
841
b'</html>'
841
842
)
842
843
844
+ elem = ET .XML ("<html><body><p>pre<br/>post</p><p>text</p></body></html>" )
845
+ ET .indent (elem , space = '' )
846
+ self .assertEqual (
847
+ ET .tostring (elem ),
848
+ b'<html>\n '
849
+ b'<body>\n '
850
+ b'<p>pre<br />post</p>\n '
851
+ b'<p>text</p>\n '
852
+ b'</body>\n '
853
+ b'</html>'
854
+ )
855
+
843
856
def test_indent_space_caching (self ):
844
857
elem = ET .XML ("<html><body><p>par</p><p>text</p><p><br/></p><p /></body></html>" )
845
858
ET .indent (elem )
@@ -856,6 +869,31 @@ def test_indent_space_caching(self):
856
869
len ({id (el .tail ) for el in elem .iter ()}),
857
870
)
858
871
872
+ def test_indent_level (self ):
873
+ elem = ET .XML ("<html><body><p>pre<br/>post</p><p>text</p></body></html>" )
874
+ ET .indent (elem , level = 2 )
875
+ self .assertEqual (
876
+ ET .tostring (elem ),
877
+ b'<html>\n '
878
+ b' <body>\n '
879
+ b' <p>pre<br />post</p>\n '
880
+ b' <p>text</p>\n '
881
+ b' </body>\n '
882
+ b' </html>'
883
+ )
884
+
885
+ elem = ET .XML ("<html><body><p>pre<br/>post</p><p>text</p></body></html>" )
886
+ ET .indent (elem , level = 1 , space = ' ' )
887
+ self .assertEqual (
888
+ ET .tostring (elem ),
889
+ b'<html>\n '
890
+ b' <body>\n '
891
+ b' <p>pre<br />post</p>\n '
892
+ b' <p>text</p>\n '
893
+ b' </body>\n '
894
+ b' </html>'
895
+ )
896
+
859
897
def test_tostring_default_namespace (self ):
860
898
elem = ET .XML ('<body xmlns="http://effbot.org/ns"><tag/></body>' )
861
899
self .assertEqual (
0 commit comments