1
1
# misc tests
2
2
3
+ import pytest
3
4
import re
4
5
import sys
6
+ import time
5
7
import unittest
6
8
7
9
import roundup .anypy .cmp_
10
12
from roundup .cgi import cgitb
11
13
from roundup .cgi .accept_language import parse
12
14
15
+ from roundup .support import PrioList , Progress , TruthDict
16
+
13
17
14
18
class AcceptLanguageTest (unittest .TestCase ):
15
19
def testParse (self ):
@@ -34,10 +38,69 @@ def testParse(self):
34
38
self .assertEqual (parse (" " ), [])
35
39
self .assertEqual (parse ("en," ), ['en' ])
36
40
41
+
37
42
class CmpTest (unittest .TestCase ):
38
43
def testCmp (self ):
39
44
roundup .anypy .cmp_ ._test ()
40
45
46
+
47
+ class PrioListTest (unittest .TestCase ):
48
+ def testPL (self ):
49
+ start_data = [(3 , 33 ), (1 , - 2 ), (2 , 10 )]
50
+ pl = PrioList (key = lambda x : x [1 ])
51
+ for i in start_data :
52
+ pl .append (i )
53
+
54
+ l = [x for x in pl ]
55
+ self .assertEqual (l , [(1 , - 2 ), (2 , 10 ), (3 , 33 )])
56
+
57
+ pl = PrioList ()
58
+ for i in start_data :
59
+ pl .append (i )
60
+
61
+ l = [x for x in pl ]
62
+ self .assertEqual (l , [(1 , - 2 ), (2 , 10 ), (3 , 33 )])
63
+
64
+ class ProgressTest (unittest .TestCase ):
65
+
66
+ @pytest .fixture (autouse = True )
67
+ def inject_fixtures (self , capsys ):
68
+ self ._capsys = capsys
69
+
70
+ def testProgress (self ):
71
+ for x in Progress ("5 Items@2 sec:" , [1 ,2 ,3 ,4 ,5 ]):
72
+ time .sleep (2 )
73
+
74
+ captured = self ._capsys .readouterr ()
75
+
76
+ split_capture = captured .out .split ('\r ' )
77
+
78
+ # lines padded to 75 characters test should be long enough to
79
+ # get an ETA printed at 100%, 80% and 60% hopefully this
80
+ # doesn't become a flakey test on different hardware.
81
+ self .assertIn ("5 Items@2 sec: 0%" .ljust (75 ),
82
+ split_capture )
83
+ self .assertIn ("5 Items@2 sec: 60% (ETA 00:00:02)" .ljust (75 ),
84
+ split_capture )
85
+ self .assertIn ("5 Items@2 sec: 100% (ETA 00:00:00)" .ljust (75 ),
86
+ split_capture )
87
+ print (captured .err )
88
+
89
+
90
+ class TruthDictTest (unittest .TestCase ):
91
+ def testTD (self ):
92
+ td = TruthDict ([])
93
+ # empty TruthDict always returns True.
94
+ self .assertTrue (td ['a' ])
95
+ self .assertTrue (td ['z' ])
96
+ self .assertTrue (td ['' ])
97
+ self .assertTrue (td [None ])
98
+
99
+ td = TruthDict (['a' , 'b' , 'c' ])
100
+ self .assertTrue (td ['a' ])
101
+ self .assertFalse (td ['z' ])
102
+
103
+
41
104
class VersionCheck (unittest .TestCase ):
42
105
def test_Version_Check (self ):
43
106
0 commit comments