subunit: Import new version.
[Samba/fernandojvsilva.git] / lib / subunit / python / subunit / tests / test_progress_model.py
blob76200c61070de74a07f0cac6be62bbe72a760ee3
2 # subunit: extensions to Python unittest to get test results from subprocesses.
3 # Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
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.
17 import unittest
19 import subunit
20 from subunit.progress_model import ProgressModel
23 class TestProgressModel(unittest.TestCase):
25 def assertProgressSummary(self, pos, total, progress):
26 """Assert that a progress model has reached a particular point."""
27 self.assertEqual(pos, progress.pos())
28 self.assertEqual(total, progress.width())
30 def test_new_progress_0_0(self):
31 progress = ProgressModel()
32 self.assertProgressSummary(0, 0, progress)
34 def test_advance_0_0(self):
35 progress = ProgressModel()
36 progress.advance()
37 self.assertProgressSummary(1, 0, progress)
39 def test_advance_1_0(self):
40 progress = ProgressModel()
41 progress.advance()
42 self.assertProgressSummary(1, 0, progress)
44 def test_set_width_absolute(self):
45 progress = ProgressModel()
46 progress.set_width(10)
47 self.assertProgressSummary(0, 10, progress)
49 def test_set_width_absolute_preserves_pos(self):
50 progress = ProgressModel()
51 progress.advance()
52 progress.set_width(2)
53 self.assertProgressSummary(1, 2, progress)
55 def test_adjust_width(self):
56 progress = ProgressModel()
57 progress.adjust_width(10)
58 self.assertProgressSummary(0, 10, progress)
59 progress.adjust_width(-10)
60 self.assertProgressSummary(0, 0, progress)
62 def test_adjust_width_preserves_pos(self):
63 progress = ProgressModel()
64 progress.advance()
65 progress.adjust_width(10)
66 self.assertProgressSummary(1, 10, progress)
67 progress.adjust_width(-10)
68 self.assertProgressSummary(1, 0, progress)
70 def test_push_preserves_progress(self):
71 progress = ProgressModel()
72 progress.adjust_width(3)
73 progress.advance()
74 progress.push()
75 self.assertProgressSummary(1, 3, progress)
77 def test_advance_advances_substack(self):
78 progress = ProgressModel()
79 progress.adjust_width(3)
80 progress.advance()
81 progress.push()
82 progress.adjust_width(1)
83 progress.advance()
84 self.assertProgressSummary(2, 3, progress)
86 def test_adjust_width_adjusts_substack(self):
87 progress = ProgressModel()
88 progress.adjust_width(3)
89 progress.advance()
90 progress.push()
91 progress.adjust_width(2)
92 progress.advance()
93 self.assertProgressSummary(3, 6, progress)
95 def test_set_width_adjusts_substack(self):
96 progress = ProgressModel()
97 progress.adjust_width(3)
98 progress.advance()
99 progress.push()
100 progress.set_width(2)
101 progress.advance()
102 self.assertProgressSummary(3, 6, progress)
104 def test_pop_restores_progress(self):
105 progress = ProgressModel()
106 progress.adjust_width(3)
107 progress.advance()
108 progress.push()
109 progress.adjust_width(1)
110 progress.advance()
111 progress.pop()
112 self.assertProgressSummary(1, 3, progress)
115 def test_suite():
116 loader = subunit.tests.TestUtil.TestLoader()
117 result = loader.loadTestsFromName(__name__)
118 return result