- commit
- 8afb3e5d0b5d0ad6f40a3e7f94185fa2b7585b44
- parent
- a7599f6a8123f5b76f69f0e2b3989b03a047a2af
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-11-05 09:58
lint
Diffstat
| M | simplecharts.py | 13 | +++---------- |
| M | test.py | 17 | ++++++++--------- |
2 files changed, 11 insertions, 19 deletions
diff --git a/simplecharts.py b/simplecharts.py
@@ -47,16 +47,9 @@ class BaseRenderer: 47 47 if '\n' in content: 48 48 lines = content.strip().split('\n') 49 49 content = '\n' + '\n'.join('\t' + l for l in lines) + '\n'50 -1 return '<{tag}{attrs}>{content}</{tag}>\n'.format(51 -1 tag=tag,52 -1 attrs=self.attrs(**attrs),53 -1 content=content,54 -1 )-1 50 return f'<{tag}{self.attrs(**attrs)}>{content}</{tag}>\n' 55 51 else:56 -1 return '<{tag}{attrs} />\n'.format(57 -1 tag=tag,58 -1 attrs=self.attrs(**attrs),59 -1 )-1 52 return f'<{tag}{self.attrs(**attrs)} />\n' 60 53 61 54 def line(self, x1, x2, y1, y2, color, **kwargs): 62 55 return self.element( @@ -163,7 +156,7 @@ class BaseRenderer: 163 156 y = -(self.padding + self.y_legend) 164 157 width = self.width + p + self.x_labels 165 158 height = self.height + p + self.y_legend + self.y_legend166 -1 return '{:g} {:g} {:g} {:g}'.format(x, y, width, height)-1 159 return f'{x:g} {y:g} {width:g} {height:g}' 167 160 168 161 def render(self, data): 169 162 if self.stacked:
diff --git a/test.py b/test.py
@@ -1,7 +1,7 @@ -1 1 import difflib -1 2 import json 1 3 import os 2 4 import sys3 -1 import json4 -1 import difflib5 5 6 6 import simplecharts 7 7 @@ -9,19 +9,18 @@ DIR = 'tests' 9 9 10 10 11 11 def render_error(actual, expected, name):12 -1 actual_lines = [line + '\n' for line in actual.split('\n')]13 -1 expected_lines = [line + '\n' for line in expected.split('\n')]14 -1 diff = difflib.unified_diff(15 -1 actual_lines, expected_lines, 'actual', name)-1 12 actual_lines = [f'{line}\n' for line in actual.split('\n')] -1 13 expected_lines = [f'{line}\n' for line in expected.split('\n')] -1 14 diff = difflib.unified_diff(actual_lines, expected_lines, 'actual', name) 16 15 sys.stdout.writelines(diff) 17 16 18 17 19 18 def run_test(key, renderer):20 -1 with open(os.path.join(DIR, key + '.json')) as fh:-1 19 with open(os.path.join(DIR, f'{key}.json')) as fh: 21 20 data = json.load(fh) 22 21 actual = renderer.render(data) 23 2224 -1 svg = '{}_{}.svg'.format(key, renderer.__class__.__name__)-1 23 svg = f'{key}_{renderer.__class__.__name__}.svg' 25 24 path = os.path.join(DIR, svg) 26 25 27 26 if os.path.exists(path): @@ -37,7 +36,7 @@ def run_test(key, renderer): 37 36 38 37 def test_round_max(i, expected): 39 38 actual = simplecharts.round_max(i)40 -1 msg = 'round_max({}) == {} != {}'.format(i, actual, expected)-1 39 msg = f'round_max({i}) == {actual} != {expected}' 41 40 assert actual == expected, msg 42 41 43 42