Skip to content

Commit 443ca15

Browse files
committed
apply-deepsource-advice
1 parent c5ea5e1 commit 443ca15

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

sparklines/__main__.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@
1010
import sys
1111
from importlib.metadata import version
1212

13-
if importlib.util.find_spec("termcolor"):
14-
HAVE_TERMCOLOR = True
15-
else:
16-
HAVE_TERMCOLOR = False
17-
1813
if sys.version_info.major >= 3:
1914
from sparklines.sparklines import sparklines, demo
2015
else:
2116
from sparklines import sparklines, demo
2217

18+
HAVE_TERMCOLOR = bool(importlib.util.find_spec("termcolor"))
19+
2320

2421
def _float_or_none(num_str):
2522
"""Convert a string to a float if possible or None."""
26-
2723
try:
2824
res = float(num_str)
2925
except ValueError:
@@ -52,15 +48,15 @@ def test_valid_number(arg):
5248

5349
def test_valid_emphasis(arg):
5450
"""Argparse validator for color filter expressions."""
55-
5651
pat = r"\w+\:(eq|gt|ge|lt|le)\:.+"
5752
if re.match(pat, arg):
5853
return arg
59-
else:
60-
raise ValueError()
54+
55+
raise ValueError()
6156

6257

6358
def main(argv=None):
59+
"""Main entry point for the CLI."""
6460
desc = """Sparklines on the command-line, e.g. ▃▁▄▁▄█▂▅ for
6561
3 1 4 1 5 9 2 6. Please add bug reports and suggestions to
6662
https://github.com/deeplook/sparklines/issues."""
@@ -93,11 +89,11 @@ def main(argv=None):
9389
"-M", "--max", type=float, help="Use this value as the maximum for scaling."
9490
)
9591

96-
help_emph = """Emphasize input values below or above a certain
92+
help_emph = f"""Emphasize input values below or above a certain
9793
threshold (e.g. "green:gt:5.0"). This option takes one argument
9894
value, but can be given repeatedly. Works only when optional
99-
dependancy "termcolor" is met (which is {0!s} here). Otherwise
100-
has no effect.""".format(HAVE_TERMCOLOR)
95+
dependancy "termcolor" is met (which is {HAVE_TERMCOLOR} here). Otherwise
96+
has no effect."""
10197
p.add_argument(
10298
"-e",
10399
"--emphasize",

tests/test_sparkline.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def strip_ansi(text):
2929

3030
def test_parse_float():
3131
"""Test parsing input numbers."""
32-
3332
t = is_valid_number
3433

3534
assert t("4.5") == "4.5"
@@ -61,15 +60,13 @@ def test_parse_float():
6160

6261
def test_scale0():
6362
"""Test scale..."""
64-
6563
res = scale_values([1, 2, 3])
6664
exp = [1.0, 4.0, 8.0]
6765
assert res == exp
6866

6967

7068
def test_scale1():
7169
"""Test scale..."""
72-
7370
res = scale_values([1, 2, 3], num_lines=2)
7471
exp = [1.0, 8.0, 16.0]
7572
assert res == exp
@@ -85,31 +82,27 @@ def test_batch():
8582

8683
def test_scale_pi():
8784
"""Test scale Pi."""
88-
8985
res = scale_values([3, 1, 4, 1, 5, 9, 2, 6])
9086
exp = [3, 1, 4, 1, 4, 8, 2, 5]
9187
assert res == exp
9288

9389

9490
def test_pi():
9591
"""Test first eight digits of Pi."""
96-
9792
res = sparklines([3, 1, 4, 1, 5, 9, 2, 6])
9893
exp = ["▃▁▄▁▄█▂▅"]
9994
assert res == exp
10095

10196

10297
def test_minmax():
10398
"""Test two values, min and max."""
104-
10599
res = sparklines([1, 8])
106100
exp = ["▁█"] # 1, 8
107101
assert res == exp
108102

109103

110104
def test_rounding0():
111105
"""Test two values, min and max."""
112-
113106
res = sparklines([1, 5, 8])
114107
exp = ["▁▅█"] # 1, 5, 8
115108
assert res == exp
@@ -141,7 +134,6 @@ def test_minimum_internal_consistency():
141134

142135
def test1():
143136
"""Test single values all have the same four pixel high output character."""
144-
145137
for i in range(10):
146138
res = sparklines([i])
147139
exp = ["▄"]
@@ -150,7 +142,6 @@ def test1():
150142

151143
def test_empty():
152144
"""Make sure degenerate cases don't fail."""
153-
154145
res = sparklines([])
155146
exp = [""]
156147
# Produces an empty line from the command line

0 commit comments

Comments
 (0)