Skip to content

Commit e84b2fc

Browse files
committed
test: add tests for support.py: PrioList, Progress, TruthDict
Also removed an obsolete comment for Progress.
1 parent c684ff9 commit e84b2fc

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

roundup/support.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def __iter__(self):
6868
class Progress:
6969
'''Progress display for console applications.
7070
71-
See __main__ block at end of file for sample usage.
7271
'''
7372
def __init__(self, info, sequence):
7473
self.info = info

test/test_misc.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# misc tests
22

3+
import pytest
34
import re
45
import sys
6+
import time
57
import unittest
68

79
import roundup.anypy.cmp_
@@ -10,6 +12,8 @@
1012
from roundup.cgi import cgitb
1113
from roundup.cgi.accept_language import parse
1214

15+
from roundup.support import PrioList, Progress, TruthDict
16+
1317

1418
class 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+
3742
class 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+
41104
class VersionCheck(unittest.TestCase):
42105
def test_Version_Check(self):
43106

0 commit comments

Comments
 (0)