11# misc tests
22
3+ import pytest
34import re
45import sys
6+ import time
57import unittest
68
79import roundup .anypy .cmp_
1012from roundup .cgi import cgitb
1113from roundup .cgi .accept_language import parse
1214
15+ from roundup .support import PrioList , Progress , TruthDict
16+
1317
1418class AcceptLanguageTest (unittest .TestCase ):
1519 def testParse (self ):
@@ -34,10 +38,69 @@ def testParse(self):
3438 self .assertEqual (parse (" " ), [])
3539 self .assertEqual (parse ("en," ), ['en' ])
3640
41+
3742class CmpTest (unittest .TestCase ):
3843 def testCmp (self ):
3944 roundup .anypy .cmp_ ._test ()
4045
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+
41104class VersionCheck (unittest .TestCase ):
42105 def test_Version_Check (self ):
43106
0 commit comments