Debian Codegraph @

python/tests/test_progress_model.py

raw
1 #
2 # subunit: extensions to Python unittest to get test results from subprocesses.
3 # Copyright (C) 2009 Robert Collins <[email protected]>
4 #
5 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6 # license at the users choice. A copy of both licenses are available in the
7 # project source as Apache-2.0 and BSD. You may not use this file except in
8 # compliance with one of these two licences.
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # license you chose for the specific language governing permissions and
14 # limitations under that license.
15 #
16
17 import unittest
18
19 from subunit.progress_model import ProgressModel
20
21
22 class TestProgressModel(unittest.TestCase):
23 def assertProgressSummary(self, pos, total, progress):
24 """Assert that a progress model has reached a particular point."""
25 self.assertEqual(pos, progress.pos())
26 self.assertEqual(total, progress.width())
27
28 def test_new_progress_0_0(self):
29 progress = ProgressModel()
30 self.assertProgressSummary(0, 0, progress)
31
32 def test_advance_0_0(self):
33 progress = ProgressModel()
34 progress.advance()
35 self.assertProgressSummary(1, 0, progress)
36
37 def test_advance_1_0(self):
38 progress = ProgressModel()
39 progress.advance()
40 self.assertProgressSummary(1, 0, progress)
41
42 def test_set_width_absolute(self):
43 progress = ProgressModel()
44 progress.set_width(10)
45 self.assertProgressSummary(0, 10, progress)
46
47 def test_set_width_absolute_preserves_pos(self):
48 progress = ProgressModel()
49 progress.advance()
50 progress.set_width(2)
51 self.assertProgressSummary(1, 2, progress)
52
53 def test_adjust_width(self):
54 progress = ProgressModel()
55 progress.adjust_width(10)
56 self.assertProgressSummary(0, 10, progress)
57 progress.adjust_width(-10)
58 self.assertProgressSummary(0, 0, progress)
59
60 def test_adjust_width_preserves_pos(self):
61 progress = ProgressModel()
62 progress.advance()
63 progress.adjust_width(10)
64 self.assertProgressSummary(1, 10, progress)
65 progress.adjust_width(-10)
66 self.assertProgressSummary(1, 0, progress)
67
68 def test_push_preserves_progress(self):
69 progress = ProgressModel()
70 progress.adjust_width(3)
71 progress.advance()
72 progress.push()
73 self.assertProgressSummary(1, 3, progress)
74
75 def test_advance_advances_substack(self):
76 progress = ProgressModel()
77 progress.adjust_width(3)
78 progress.advance()
79 progress.push()
80 progress.adjust_width(1)
81 progress.advance()
82 self.assertProgressSummary(2, 3, progress)
83
84 def test_adjust_width_adjusts_substack(self):
85 progress = ProgressModel()
86 progress.adjust_width(3)
87 progress.advance()
88 progress.push()
89 progress.adjust_width(2)
90 progress.advance()
91 self.assertProgressSummary(3, 6, progress)
92
93 def test_set_width_adjusts_substack(self):
94 progress = ProgressModel()
95 progress.adjust_width(3)
96 progress.advance()
97 progress.push()
98 progress.set_width(2)
99 progress.advance()
100 self.assertProgressSummary(3, 6, progress)
101
102 def test_pop_restores_progress(self):
103 progress = ProgressModel()
104 progress.adjust_width(3)
105 progress.advance()
106 progress.push()
107 progress.adjust_width(1)
108 progress.advance()
109 progress.pop()
110 self.assertProgressSummary(1, 3, progress)