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.
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.
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()
37
self.assertProgressSummary(1, 0, progress)
39
def test_advance_1_0(self):
40
progress = ProgressModel()
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()
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()
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)
75
self.assertProgressSummary(1, 3, progress)
77
def test_advance_advances_substack(self):
78
progress = ProgressModel()
79
progress.adjust_width(3)
82
progress.adjust_width(1)
84
self.assertProgressSummary(2, 3, progress)
86
def test_adjust_width_adjusts_substack(self):
87
progress = ProgressModel()
88
progress.adjust_width(3)
91
progress.adjust_width(2)
93
self.assertProgressSummary(3, 6, progress)
95
def test_set_width_adjusts_substack(self):
96
progress = ProgressModel()
97
progress.adjust_width(3)
100
progress.set_width(2)
102
self.assertProgressSummary(3, 6, progress)
104
def test_pop_restores_progress(self):
105
progress = ProgressModel()
106
progress.adjust_width(3)
109
progress.adjust_width(1)
112
self.assertProgressSummary(1, 3, progress)
116
loader = subunit.tests.TestUtil.TestLoader()
117
result = loader.loadTestsFromName(__name__)