summaryrefslogtreecommitdiff
path: root/gerbonara/tests/test_cli.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-02-21 23:43:59 +0100
committerjaseg <git@jaseg.de>2023-02-21 23:43:59 +0100
commit70179a4178d6574182cbc80de211a933b79ffa8a (patch)
tree1fca0d9c6978e133f97a118984847318fb047f5e /gerbonara/tests/test_cli.py
parent866eafb4eb1648483877125e838af79cd6c156e5 (diff)
downloadgerbonara-70179a4178d6574182cbc80de211a933b79ffa8a.tar.gz
gerbonara-70179a4178d6574182cbc80de211a933b79ffa8a.tar.bz2
gerbonara-70179a4178d6574182cbc80de211a933b79ffa8a.zip
Finish first batch of render tests
Diffstat (limited to 'gerbonara/tests/test_cli.py')
-rw-r--r--gerbonara/tests/test_cli.py77
1 files changed, 76 insertions, 1 deletions
diff --git a/gerbonara/tests/test_cli.py b/gerbonara/tests/test_cli.py
index b42a216..e085894 100644
--- a/gerbonara/tests/test_cli.py
+++ b/gerbonara/tests/test_cli.py
@@ -16,10 +16,15 @@
# limitations under the License.
#
+import math
from pathlib import Path
+import re
+import tempfile
+import json
import pytest
from click.testing import CliRunner
+from bs4 import BeautifulSoup
from .utils import *
from ..cli import render, rewrite, transform, merge, bounding_box, layers, meta
@@ -28,7 +33,6 @@ class TestRender:
def invoke(self, *args):
runner = CliRunner()
res = runner.invoke(render, list(map(str, args)))
- print(res.output)
assert res.exit_code == 0
return res.output
@@ -40,3 +44,74 @@ class TestRender:
with pytest.warns(UserWarning):
self.invoke(reference, '--warnings=once')
+ @pytest.mark.parametrize('reference', ['kicad-older'], indirect=True)
+ def test_side(self, reference):
+ without = self.invoke(reference, '--warnings=ignore')
+ top = self.invoke(reference, '--top', '--warnings=ignore')
+ bottom = self.invoke(reference, '--bottom', '--warnings=ignore')
+ assert top.strip().startswith('<?xml')
+ assert bottom.strip().startswith('<?xml')
+ assert '<path' in top
+ assert '<path' in bottom
+ assert top == without
+ assert top != bottom
+
+ @pytest.mark.parametrize('reference', ['kicad-older'], indirect=True)
+ def test_margin(self, reference):
+ no_margin = BeautifulSoup(self.invoke(reference, '--top', '--warnings=ignore'), features='xml')
+ with_margin = BeautifulSoup(self.invoke(reference, '--top', '--warnings=ignore', '--margin=25'), features='xml')
+
+ s = no_margin.find('svg')
+ w_no = float(s['width'].rstrip('m'))
+ h_no = float(s['height'].rstrip('m'))
+
+ s = with_margin.find('svg')
+ w_with = float(s['width'].rstrip('m'))
+ h_with = float(s['height'].rstrip('m'))
+
+ assert math.isclose(w_with, w_no+2*25, abs_tol=1e-6)
+ assert math.isclose(h_with, h_no+2*25, abs_tol=1e-6)
+
+ @pytest.mark.parametrize('reference', ['kicad-older'], indirect=True)
+ def test_force_bounds(self, reference):
+ out = self.invoke(reference, '--top', '--warnings=ignore', '--force-bounds=10,10,50,50')
+ s = BeautifulSoup(out, features='xml').find('svg')
+ w = float(s['width'].rstrip('m'))
+ h = float(s['height'].rstrip('m'))
+
+ assert math.isclose(w, 40, abs_tol=1e-6)
+ assert math.isclose(h, 40, abs_tol=1e-6)
+
+ @pytest.mark.parametrize('reference', ['kicad-older'], indirect=True)
+ def test_inkscape(self, reference):
+ out_with = self.invoke(reference, '--top', '--warnings=ignore', '--inkscape')
+ out_without = self.invoke(reference, '--top', '--warnings=ignore', '--standard-svg')
+ assert 'sodipodi' in out_with
+ assert 'sodipodi' not in out_without
+
+ @pytest.mark.parametrize('reference', ['kicad-older'], indirect=True)
+ def test_colorscheme(self, reference):
+ out_without = self.invoke(reference, '--top', '--warnings=ignore')
+ find_colors = lambda s: { m.group(0) for m in re.finditer(r'#[0-9a-fA-F]{6,}', s) }
+ colors_without = find_colors(out_without)
+
+ test_colorscheme = {
+ 'copper': '#012345',
+ 'mask': '#67890abc',
+ 'paste': '#def012',
+ 'silk': '#345678',
+ 'drill': '#90abcd',
+ 'outline': '#ff0123',
+ }
+
+ with tempfile.NamedTemporaryFile('w', suffix='.json') as f:
+ json.dump(test_colorscheme, f)
+ f.flush()
+
+ out_with = self.invoke(reference, '--top', '--warnings=ignore', f'--colorscheme={f.name}')
+ for color in colors_without:
+ colors_with = find_colors(out_with)
+ assert not colors_without & colors_with
+ assert len(colors_without) == len(colors_with)
+ assert colors_with - {'#67890a'} == set(test_colorscheme.values()) - {'#67890abc'}
+