11"""Tests util functions."""
22
3- from unittest .mock import patch
4-
53import pytest
64
75from sphinx .testing .util import strip_escseq
@@ -23,37 +21,46 @@ def test_display_chunk():
2321
2422
2523@pytest .mark .sphinx ('dummy' )
26- @patch ('sphinx.util.console._tw' , 40 ) # terminal width = 40
27- def test_status_iterator (app , status , warning ):
24+ def test_status_iterator_length_0 (app , status , warning ):
2825 logging .setup (app , status , warning )
2926
30- # # test for old_status_iterator
31- # status.seek(0)
32- # status.truncate(0)
33- # yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... '))
34- # output = strip_escseq(status.getvalue())
35- # assert 'testing ... hello sphinx world \n' in output
36- # assert yields == ['hello', 'sphinx', 'world']
27+ # test for status_iterator (length=0)
28+ status .seek (0 )
29+ status .truncate (0 )
30+ yields = list (status_iterator (['hello' , 'sphinx' , 'world' ], 'testing ... ' ))
31+ output = strip_escseq (status .getvalue ())
32+ assert 'testing ... hello sphinx world \n ' in output
33+ assert yields == ['hello' , 'sphinx' , 'world' ]
34+
35+
36+ @pytest .mark .sphinx ('dummy' )
37+ def test_status_iterator_verbosity_0 (app , status , warning ):
38+ logging .setup (app , status , warning )
3739
3840 # test for status_iterator (verbosity=0)
3941 status .seek (0 )
4042 status .truncate (0 )
4143 yields = list (status_iterator (['hello' , 'sphinx' , 'world' ], 'testing ... ' ,
4244 length = 3 , verbosity = 0 ))
4345 output = strip_escseq (status .getvalue ())
44- assert 'testing ... [ 33%] hello \r ' in output
45- assert 'testing ... [ 66 %] sphinx \r ' in output
46- assert 'testing ... [100%] world \r \n ' in output
46+ assert 'testing ... [ 33%] hello\r ' in output
47+ assert 'testing ... [ 67 %] sphinx\r ' in output
48+ assert 'testing ... [100%] world\r \n ' in output
4749 assert yields == ['hello' , 'sphinx' , 'world' ]
4850
51+
52+ @pytest .mark .sphinx ('dummy' )
53+ def test_status_iterator_verbosity_1 (app , status , warning ):
54+ logging .setup (app , status , warning )
55+
4956 # test for status_iterator (verbosity=1)
5057 status .seek (0 )
5158 status .truncate (0 )
5259 yields = list (status_iterator (['hello' , 'sphinx' , 'world' ], 'testing ... ' ,
5360 length = 3 , verbosity = 1 ))
5461 output = strip_escseq (status .getvalue ())
5562 assert 'testing ... [ 33%] hello\n ' in output
56- assert 'testing ... [ 66 %] sphinx\n ' in output
63+ assert 'testing ... [ 67 %] sphinx\n ' in output
5764 assert 'testing ... [100%] world\n \n ' in output
5865 assert yields == ['hello' , 'sphinx' , 'world' ]
5966
0 commit comments