Improved coverage · commit-0/python-progressbar@b8dbc12 · GitHub
Skip to content

Commit b8dbc12

Browse files
committed
Improved coverage
1 parent eb35f2f commit b8dbc12

9 files changed

Lines changed: 153 additions & 91 deletions

File tree

.coveragerc

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples.py

Lines changed: 8 additions & 1 deletion

progressbar/multi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ def _render_finished_bar(
264264
if not self.show_finished:
265265
return
266266

267-
if bar_.finished():
267+
if bar_.finished(): # pragma: no branch
268268
if self.finished_format is None:
269269
update(force=False)
270-
else:
270+
else: # pragma: no cover
271271
yield self.finished_format.format(label=bar_.label)
272272

273273
def print(

progressbar/terminal/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,8 @@
10591059

10601060
# Check if the background is light or dark. This is by no means a foolproof
10611061
# method, but there is no reliable way to detect this.
1062-
if os.environ.get('COLORFGBG', '15;0').split(';')[-1] == str(white.xterm):
1062+
_colorfgbg = os.environ.get('COLORFGBG', '15;0').split(';')
1063+
if _colorfgbg[-1] == str(white.xterm): # pragma: no cover
10631064
# Light background
10641065
gradient = light_gradient
10651066
primary = black

progressbar/widgets.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ def get_values(self, progress: ProgressBarMixinBase, data: Data):
12111211
if frac:
12121212
ranges[pos + 1] += frac
12131213

1214-
if self.fill_left:
1214+
if self.fill_left: # pragma: no branch
12151215
ranges = list(reversed(ranges))
12161216

12171217
return ranges
@@ -1532,18 +1532,18 @@ def __call__(
15321532
marker = self.success_marker
15331533
fg_color = self.success_fg_color
15341534
bg_color = self.success_bg_color
1535-
elif status is False:
1535+
elif status is False: # pragma: no branch
15361536
marker = self.failure_marker
15371537
fg_color = self.failure_fg_color
15381538
bg_color = self.failure_bg_color
1539-
else:
1539+
else: # pragma: no cover
15401540
marker = status
15411541
fg_color = bg_color = None
15421542

15431543
marker = converters.to_unicode(marker)
1544-
if fg_color:
1544+
if fg_color: # pragma: no branch
15451545
marker = fg_color.fg(marker)
1546-
if bg_color:
1546+
if bg_color: # pragma: no cover
15471547
marker = bg_color.bg(marker)
15481548

15491549
self.job_markers.append(marker)
@@ -1553,9 +1553,9 @@ def __call__(
15531553
fill = converters.to_unicode(self.fill(progress, data, width))
15541554
fill = self._apply_colors(fill * width, data)
15551555

1556-
if self.fill_left:
1556+
if self.fill_left: # pragma: no branch
15571557
marker += fill
1558-
else:
1558+
else: # pragma: no cover
15591559
marker = fill + marker
15601560
else:
15611561
marker = ''

pyproject.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,35 @@ exclude = [
148148
'^tests/original_examples.py$',
149149
'^examples.py$',
150150
]
151+
152+
[tool.coverage.run]
153+
branch = true
154+
source = [
155+
'progressbar',
156+
'tests',
157+
]
158+
omit = [
159+
'*/mock/*',
160+
'*/nose/*',
161+
'.tox/*',
162+
'*/os_specific/*',
163+
]
164+
[tool.coverage.paths]
165+
source = [
166+
'progressbar',
167+
]
168+
[tool.coverage.report]
169+
fail_under = 100
170+
exclude_lines = [
171+
'pragma: no cover',
172+
'@abc.abstractmethod',
173+
'def __repr__',
174+
'if self.debug:',
175+
'if settings.DEBUG',
176+
'raise AssertionError',
177+
'raise NotImplementedError',
178+
'if 0:',
179+
'if __name__ == .__main__.:',
180+
'if types.TYPE_CHECKING:',
181+
'@typing.overload',
182+
]

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ addopts =
99
--cov-report=term-missing
1010
--cov-report=xml
1111
--cov-append
12+
--cov-config=pyproject.toml
1213
--no-cov-on-fail
1314
--doctest-modules
1415

tests/test_color.py

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import typing
44

5+
import pytest
6+
57
import progressbar
68
import progressbar.env
79
import progressbar.terminal
8-
import pytest
910
from progressbar import env, terminal, widgets
10-
from progressbar.terminal import Colors, apply_colors, colors
11+
from progressbar.terminal import apply_colors, Colors, colors
1112

1213

1314
@pytest.mark.parametrize(
@@ -52,7 +53,7 @@ def test_color_environment_variables(monkeypatch, variable):
5253
'xterm-256',
5354
'xterm',
5455
],
55-
)
56+
)
5657
def test_color_support_from_env(monkeypatch, variable, value):
5758
monkeypatch.setenv('JUPYTER_COLUMNS', '')
5859
monkeypatch.setenv('JUPYTER_LINES', '')
@@ -222,63 +223,63 @@ def test_rgb_to_hls(rgb, hls):
222223
('test', None, None, None, None, None, 'test'),
223224
('test', None, None, None, None, 1, 'test'),
224225
(
225-
'test',
226-
None,
227-
None,
228-
None,
229-
colors.red,
230-
None,
231-
'\x1b[48;5;9mtest\x1b[49m',
226+
'test',
227+
None,
228+
None,
229+
None,
230+
colors.red,
231+
None,
232+
'\x1b[48;5;9mtest\x1b[49m',
232233
),
233234
(
234-
'test',
235-
None,
236-
colors.green,
237-
None,
238-
colors.red,
239-
None,
240-
'\x1b[48;5;9mtest\x1b[49m',
235+
'test',
236+
None,
237+
colors.green,
238+
None,
239+
colors.red,
240+
None,
241+
'\x1b[48;5;9mtest\x1b[49m',
241242
),
242243
('test', None, colors.red, None, None, 1, '\x1b[48;5;9mtest\x1b[49m'),
243244
('test', None, colors.red, None, None, None, 'test'),
244245
(
245-
'test',
246-
colors.green,
247-
None,
248-
colors.red,
249-
None,
250-
None,
251-
'\x1b[38;5;9mtest\x1b[39m',
246+
'test',
247+
colors.green,
248+
None,
249+
colors.red,
250+
None,
251+
None,
252+
'\x1b[38;5;9mtest\x1b[39m',
252253
),
253254
(
254-
'test',
255-
colors.green,
256-
colors.red,
257-
None,
258-
None,
259-
1,
260-
'\x1b[48;5;9m\x1b[38;5;2mtest\x1b[39m\x1b[49m',
255+
'test',
256+
colors.green,
257+
colors.red,
258+
None,
259+
None,
260+
1,
261+
'\x1b[48;5;9m\x1b[38;5;2mtest\x1b[39m\x1b[49m',
261262
),
262263
('test', colors.red, None, None, None, 1, '\x1b[38;5;9mtest\x1b[39m'),
263264
('test', colors.red, None, None, None, None, 'test'),
264265
('test', colors.red, colors.red, None, None, None, 'test'),
265266
(
266-
'test',
267-
colors.red,
268-
colors.yellow,
269-
None,
270-
None,
271-
1,
272-
'\x1b[48;5;11m\x1b[38;5;9mtest\x1b[39m\x1b[49m',
267+
'test',
268+
colors.red,
269+
colors.yellow,
270+
None,
271+
None,
272+
1,
273+
'\x1b[48;5;11m\x1b[38;5;9mtest\x1b[39m\x1b[49m',
273274
),
274275
(
275-
'test',
276-
colors.red,
277-
colors.yellow,
278-
None,
279-
None,
280-
1,
281-
'\x1b[48;5;11m\x1b[38;5;9mtest\x1b[39m\x1b[49m',
276+
'test',
277+
colors.red,
278+
colors.yellow,
279+
None,
280+
None,
281+
1,
282+
'\x1b[48;5;11m\x1b[38;5;9mtest\x1b[39m\x1b[49m',
282283
),
283284
],
284285
)
@@ -290,13 +291,39 @@ def test_apply_colors(text, fg, bg, fg_none, bg_none, percentage, expected,
290291
progressbar.env.ColorSupport.XTERM_256,
291292
)
292293
assert (
293-
apply_colors(
294-
text,
295-
fg=fg,
296-
bg=bg,
297-
fg_none=fg_none,
298-
bg_none=bg_none,
299-
percentage=percentage,
300-
)
301-
== expected
294+
apply_colors(
295+
text,
296+
fg=fg,
297+
bg=bg,
298+
fg_none=fg_none,
299+
bg_none=bg_none,
300+
percentage=percentage,
301+
)
302+
== expected
302303
)
304+
305+
306+
def test_ansi_color(monkeypatch):
307+
color = progressbar.terminal.Color(
308+
colors.red.rgb,
309+
colors.red.hls,
310+
'red-ansi',
311+
None,
312+
)
313+
314+
for color_support in {
315+
env.ColorSupport.NONE,
316+
env.ColorSupport.XTERM,
317+
env.ColorSupport.XTERM_256,
318+
env.ColorSupport.XTERM_TRUECOLOR,
319+
}:
320+
monkeypatch.setattr(
321+
env,
322+
'COLOR_SUPPORT',
323+
color_support,
324+
)
325+
assert color.ansi is not None or color_support == env.ColorSupport.NONE
326+
327+
328+
def test_sgr_call():
329+
assert progressbar.terminal.encircled('test') == '\x1b[52mtest\x1b[54m'

tests/test_job_status.py

Lines changed: 20 additions & 0 deletions

0 commit comments

Comments
 (0)