1
1
"""Tests util functions."""
2
2
3
- from unittest .mock import patch
4
-
5
3
import pytest
6
4
7
5
from sphinx .testing .util import strip_escseq
@@ -23,37 +21,46 @@ def test_display_chunk():
23
21
24
22
25
23
@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 ):
28
25
logging .setup (app , status , warning )
29
26
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 )
37
39
38
40
# test for status_iterator (verbosity=0)
39
41
status .seek (0 )
40
42
status .truncate (0 )
41
43
yields = list (status_iterator (['hello' , 'sphinx' , 'world' ], 'testing ... ' ,
42
44
length = 3 , verbosity = 0 ))
43
45
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
47
49
assert yields == ['hello' , 'sphinx' , 'world' ]
48
50
51
+
52
+ @pytest .mark .sphinx ('dummy' )
53
+ def test_status_iterator_verbosity_1 (app , status , warning ):
54
+ logging .setup (app , status , warning )
55
+
49
56
# test for status_iterator (verbosity=1)
50
57
status .seek (0 )
51
58
status .truncate (0 )
52
59
yields = list (status_iterator (['hello' , 'sphinx' , 'world' ], 'testing ... ' ,
53
60
length = 3 , verbosity = 1 ))
54
61
output = strip_escseq (status .getvalue ())
55
62
assert 'testing ... [ 33%] hello\n ' in output
56
- assert 'testing ... [ 66 %] sphinx\n ' in output
63
+ assert 'testing ... [ 67 %] sphinx\n ' in output
57
64
assert 'testing ... [100%] world\n \n ' in output
58
65
assert yields == ['hello' , 'sphinx' , 'world' ]
59
66
0 commit comments