summaryrefslogtreecommitdiff
path: root/gerbonara/tests/test_cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'gerbonara/tests/test_cli.py')
-rw-r--r--gerbonara/tests/test_cli.py93
1 files changed, 91 insertions, 2 deletions
diff --git a/gerbonara/tests/test_cli.py b/gerbonara/tests/test_cli.py
index e085894..d5a0ad4 100644
--- a/gerbonara/tests/test_cli.py
+++ b/gerbonara/tests/test_cli.py
@@ -21,18 +21,34 @@ from pathlib import Path
import re
import tempfile
import json
+from unittest import mock
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
+from .. import cli
+from ..utils import MM
+
+
+@pytest.fixture()
+def file_mock():
+ old = cli.GerberFile
+ c_obj = cli.GerberFile = mock.Mock()
+ i_obj = c_obj.open.return_value = mock.Mock()
+ i_obj.bounding_box.return_value = (0, 0), (50, 100)
+ yield i_obj
+ cli.GerberFile = old
+
class TestRender:
def invoke(self, *args):
runner = CliRunner()
- res = runner.invoke(render, list(map(str, args)))
+ res = runner.invoke(cli.render, list(map(str, args)))
+ print(res.output)
+ if res.exception:
+ raise res.exception
assert res.exit_code == 0
return res.output
@@ -115,3 +131,76 @@ class TestRender:
assert len(colors_without) == len(colors_with)
assert colors_with - {'#67890a'} == set(test_colorscheme.values()) - {'#67890abc'}
+
+class TestRewrite:
+ def invoke(self, *args):
+ runner = CliRunner()
+ res = runner.invoke(cli.rewrite, list(map(str, args)))
+ print(res.output)
+ if res.exception:
+ raise res.exception
+ assert res.exit_code == 0
+ return res.output
+
+ def test_basic(self):
+ assert self.invoke('--version').startswith('Version ')
+
+ @pytest.mark.parametrize('reference', ['example_flash_obround.gbr'], indirect=True)
+ def test_transforms(self, reference, file_mock):
+ with tempfile.NamedTemporaryFile() as tmpout:
+ self.invoke(reference, tmpout.name, '--transform', 'rotate(90); translate(10, 10); rotate(-45.5); scale(2)')
+ file_mock.rotate.assert_has_calls([
+ mock.call(math.radians(90), 0, 0, MM),
+ mock.call(math.radians(-45.5), 0, 0, MM)])
+ file_mock.offset.assert_called_with(10, 10, MM)
+ file_mock.scale.assert_called_with(2)
+ assert file_mock.save.called
+ assert file_mock.save.call_args[0][0] == tmpout.name
+
+ @pytest.mark.parametrize('reference', ['example_flash_obround.gbr'], indirect=True)
+ def test_real_invocation(self, reference):
+ with tempfile.NamedTemporaryFile() as tmpout:
+ self.invoke(reference, tmpout.name, '--transform', 'rotate(45); translate(10, 0)')
+ assert tmpout.read()
+
+
+class TestMerge:
+ def invoke(self, *args):
+ runner = CliRunner()
+ res = runner.invoke(cli.merge, list(map(str, args)))
+ if res.exception:
+ raise res.exception
+ assert res.exit_code == 0
+ return res.output
+
+ def test_basic(self):
+ assert self.invoke('--version').startswith('Version ')
+
+ @pytest.mark.parametrize('file_a', ['kicad-older'])
+ @pytest.mark.parametrize('file_b', ['eagle-newer'])
+ def test_real_invocation(self, file_a, file_b):
+ with tempfile.TemporaryDirectory() as outdir:
+ self.invoke(reference_path(file_a), '--rotation', '90', '--offset', '0,0',
+ reference_path(file_b), '--offset', '100,100', '--rotation', '0',
+ outdir, '--output-naming-scheme', 'kicad', '--output-board-name', 'foobar',
+ '--warnings', 'ignore')
+ assert (Path(outdir) / 'foobar-F.Cu.gbr').exists()
+
+
+class TestMeta:
+ def invoke(self, *args):
+ runner = CliRunner()
+ res = runner.invoke(cli.meta, list(map(str, args)))
+ print(res.output)
+ if res.exception:
+ raise res.exception
+ assert res.exit_code == 0
+ return res.output
+
+ def test_basic(self):
+ assert self.invoke('--version').startswith('Version ')
+
+ @pytest.mark.parametrize('reference', ['example_flash_obround.gbr'], indirect=True)
+ def test_real_invocation(self, reference):
+ j = json.loads(self.invoke(reference, '--warnings', 'ignore'))
+