forked from althonos/InstaLooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pbar.py
75 lines (52 loc) · 1.91 KB
/
test_pbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# coding: utf-8
from __future__ import absolute_import
from __future__ import unicode_literals
import threading
import unittest
import warnings
import six
from instalooter.pbar import ProgressBar, TqdmProgressBar
class TestProgressBar(unittest.TestCase):
def test_derived_progress_bar(self):
class MyProgressBar(ProgressBar):
_test = {"update": 0, "max": None}
def update(self):
self._test['update'] += 1
def set_maximum(self, maximum):
self._test['max'] = maximum
pb = MyProgressBar(iter(range(10)))
self.assertEqual(pb._test['update'], 0)
self.assertIs(pb._test['max'], None)
self.assertEqual(next(pb), 0)
self.assertEqual(pb._test['update'], 1)
pb.set_maximum(10)
self.assertEqual(pb._test['max'], 10)
self.assertEqual(list(pb), list(range(1, 10)))
self.assertRaises(StopIteration, next, pb)
self.assertEqual(pb._test['update'], 10)
pb.finish()
self.assertRaises(RuntimeError, pb.get_lock)
lock = threading.RLock()
pb.set_lock(lock)
self.assertIs(pb.get_lock(), lock)
def test_tqdm_progress_bar(self):
fh = six.moves.StringIO()
pb = TqdmProgressBar(iter(range(10)), file=fh)
self.assertEqual(pb.n, 0)
self.assertIs(pb.total, None)
self.assertEqual(next(pb), 0)
self.assertEqual(pb.n, 1)
self.assertIs(pb.total, None)
pb.set_maximum(10)
self.assertEqual(pb.total, 10)
self.assertEqual(list(pb), list(range(1, 10)))
self.assertRaises(StopIteration, next, pb)
self.assertEqual(pb.n, 10)
pb.finish()
lock = threading.RLock()
pb.set_lock(lock)
self.assertIs(pb.get_lock(), lock)
def setUpModule():
warnings.simplefilter('ignore')
def tearDownModule():
warnings.simplefilter(warnings.defaultaction)