summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-13 20:33:19 +0200
committerjaseg <git@jaseg.de>2021-06-13 20:33:19 +0200
commitd0f836ecfadacbaea20fc6a3ceebd455e96e1307 (patch)
tree48b63dac21cf2849dbbf287947cb926081e0105e
parent7bebf9fe62dad33867ba6df1c0c611f8b313c549 (diff)
downloadgerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.tar.gz
gerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.tar.bz2
gerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.zip
Port old pcb-tools-extension unit tests to pytest
-rw-r--r--gerbonara/gerber/tests/panelize/__init__.py (renamed from tests/__init__.py)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_drill_inch.txt (renamed from tests/data/ref_drill_inch.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_drill_metric.txt (renamed from tests/data/ref_drill_metric.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_dxf_complex.dxf (renamed from tests/data/ref_dxf_complex.dxf)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_dxf_metric.dxf (renamed from tests/data/ref_dxf_metric.dxf)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_gerber_inch.gtl (renamed from tests/data/ref_gerber_inch.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_gerber_metric.gtl (renamed from tests/data/ref_gerber_metric.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/data/ref_gerber_single_quadrant.gtl (renamed from tests/data/ref_gerber_single_quadrant.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_offset.gtl (renamed from tests/expects/RS2724x_offset.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_rotate.gtl (renamed from tests/expects/RS2724x_rotate.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_save.gtl (renamed from tests/expects/RS2724x_save.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_single_quadrant.gtl (renamed from tests/expects/RS2724x_single_quadrant.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_to_inch.gtl (renamed from tests/expects/RS2724x_to_inch.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/RS2724x_to_metric.gtl (renamed from tests/expects/RS2724x_to_metric.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_complex_fill.gtl (renamed from tests/expects/dxf_complex_fill.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_complex_fill_flip.gtl (renamed from tests/expects/dxf_complex_fill_flip.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_offset.gtl (renamed from tests/expects/dxf_offset.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_rectangle_inch.gtl (renamed from tests/expects/dxf_rectangle_inch.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_rectangle_metric.gtl (renamed from tests/expects/dxf_rectangle_metric.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_rotate.gtl (renamed from tests/expects/dxf_rotate.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_fill.gtl (renamed from tests/expects/dxf_save_fill.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_fill_simple.gtl (renamed from tests/expects/dxf_save_fill_simple.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_line.gtl (renamed from tests/expects/dxf_save_line.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_line.txt (renamed from tests/expects/dxf_save_line.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.gtl (renamed from tests/expects/dxf_save_mousebites.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.txt (renamed from tests/expects/dxf_save_mousebites.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/dxf_to_inch.gtl (renamed from tests/expects/dxf_to_inch.gtl)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/excellon_offset.txt (renamed from tests/expects/excellon_offset.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/excellon_rotate.txt (renamed from tests/expects/excellon_rotate.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/excellon_save.txt (renamed from tests/expects/excellon_save.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/excellon_to_inch.txt (renamed from tests/expects/excellon_to_inch.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/expects/excellon_to_metric.txt (renamed from tests/expects/excellon_to_metric.txt)0
-rw-r--r--gerbonara/gerber/tests/panelize/test_am_expression.py (renamed from tests/test_am_expression.py)10
-rw-r--r--gerbonara/gerber/tests/panelize/test_dxf.py132
-rw-r--r--gerbonara/gerber/tests/panelize/test_excellon.py60
-rw-r--r--gerbonara/gerber/tests/panelize/test_rs274x.py66
-rw-r--r--gerbonara/gerber/tests/panelize/test_utility.py (renamed from tests/test_utility.py)4
-rw-r--r--tests/test_dxf.py153
-rw-r--r--tests/test_excellon.py72
-rw-r--r--tests/test_rs274x.py76
40 files changed, 263 insertions, 310 deletions
diff --git a/tests/__init__.py b/gerbonara/gerber/tests/panelize/__init__.py
index e69de29..e69de29 100644
--- a/tests/__init__.py
+++ b/gerbonara/gerber/tests/panelize/__init__.py
diff --git a/tests/data/ref_drill_inch.txt b/gerbonara/gerber/tests/panelize/data/ref_drill_inch.txt
index 6af5494..6af5494 100644
--- a/tests/data/ref_drill_inch.txt
+++ b/gerbonara/gerber/tests/panelize/data/ref_drill_inch.txt
diff --git a/tests/data/ref_drill_metric.txt b/gerbonara/gerber/tests/panelize/data/ref_drill_metric.txt
index 3a50856..3a50856 100644
--- a/tests/data/ref_drill_metric.txt
+++ b/gerbonara/gerber/tests/panelize/data/ref_drill_metric.txt
diff --git a/tests/data/ref_dxf_complex.dxf b/gerbonara/gerber/tests/panelize/data/ref_dxf_complex.dxf
index b9a89da..b9a89da 100644
--- a/tests/data/ref_dxf_complex.dxf
+++ b/gerbonara/gerber/tests/panelize/data/ref_dxf_complex.dxf
diff --git a/tests/data/ref_dxf_metric.dxf b/gerbonara/gerber/tests/panelize/data/ref_dxf_metric.dxf
index 8861d4b..8861d4b 100644
--- a/tests/data/ref_dxf_metric.dxf
+++ b/gerbonara/gerber/tests/panelize/data/ref_dxf_metric.dxf
diff --git a/tests/data/ref_gerber_inch.gtl b/gerbonara/gerber/tests/panelize/data/ref_gerber_inch.gtl
index 3ec60d8..3ec60d8 100644
--- a/tests/data/ref_gerber_inch.gtl
+++ b/gerbonara/gerber/tests/panelize/data/ref_gerber_inch.gtl
diff --git a/tests/data/ref_gerber_metric.gtl b/gerbonara/gerber/tests/panelize/data/ref_gerber_metric.gtl
index 8dfbdd4..8dfbdd4 100644
--- a/tests/data/ref_gerber_metric.gtl
+++ b/gerbonara/gerber/tests/panelize/data/ref_gerber_metric.gtl
diff --git a/tests/data/ref_gerber_single_quadrant.gtl b/gerbonara/gerber/tests/panelize/data/ref_gerber_single_quadrant.gtl
index f31f1e7..f31f1e7 100644
--- a/tests/data/ref_gerber_single_quadrant.gtl
+++ b/gerbonara/gerber/tests/panelize/data/ref_gerber_single_quadrant.gtl
diff --git a/tests/expects/RS2724x_offset.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_offset.gtl
index 3dc3e6a..3dc3e6a 100644
--- a/tests/expects/RS2724x_offset.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_offset.gtl
diff --git a/tests/expects/RS2724x_rotate.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_rotate.gtl
index f7c82cd..f7c82cd 100644
--- a/tests/expects/RS2724x_rotate.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_rotate.gtl
diff --git a/tests/expects/RS2724x_save.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_save.gtl
index 5053d99..5053d99 100644
--- a/tests/expects/RS2724x_save.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_save.gtl
diff --git a/tests/expects/RS2724x_single_quadrant.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_single_quadrant.gtl
index dbec705..dbec705 100644
--- a/tests/expects/RS2724x_single_quadrant.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_single_quadrant.gtl
diff --git a/tests/expects/RS2724x_to_inch.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_to_inch.gtl
index cb9234e..cb9234e 100644
--- a/tests/expects/RS2724x_to_inch.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_to_inch.gtl
diff --git a/tests/expects/RS2724x_to_metric.gtl b/gerbonara/gerber/tests/panelize/expects/RS2724x_to_metric.gtl
index a8efda8..a8efda8 100644
--- a/tests/expects/RS2724x_to_metric.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/RS2724x_to_metric.gtl
diff --git a/tests/expects/dxf_complex_fill.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_complex_fill.gtl
index e667789..e667789 100644
--- a/tests/expects/dxf_complex_fill.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_complex_fill.gtl
diff --git a/tests/expects/dxf_complex_fill_flip.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_complex_fill_flip.gtl
index 1f91be3..1f91be3 100644
--- a/tests/expects/dxf_complex_fill_flip.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_complex_fill_flip.gtl
diff --git a/tests/expects/dxf_offset.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_offset.gtl
index df1b015..df1b015 100644
--- a/tests/expects/dxf_offset.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_offset.gtl
diff --git a/tests/expects/dxf_rectangle_inch.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_rectangle_inch.gtl
index c196f92..c196f92 100644
--- a/tests/expects/dxf_rectangle_inch.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_rectangle_inch.gtl
diff --git a/tests/expects/dxf_rectangle_metric.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_rectangle_metric.gtl
index 092471f..092471f 100644
--- a/tests/expects/dxf_rectangle_metric.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_rectangle_metric.gtl
diff --git a/tests/expects/dxf_rotate.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_rotate.gtl
index 5c04b64..5c04b64 100644
--- a/tests/expects/dxf_rotate.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_rotate.gtl
diff --git a/tests/expects/dxf_save_fill.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_save_fill.gtl
index 4b82fb2..4b82fb2 100644
--- a/tests/expects/dxf_save_fill.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_fill.gtl
diff --git a/tests/expects/dxf_save_fill_simple.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_save_fill_simple.gtl
index 5ff4d55..5ff4d55 100644
--- a/tests/expects/dxf_save_fill_simple.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_fill_simple.gtl
diff --git a/tests/expects/dxf_save_line.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_save_line.gtl
index b3ee8f1..b3ee8f1 100644
--- a/tests/expects/dxf_save_line.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_line.gtl
diff --git a/tests/expects/dxf_save_line.txt b/gerbonara/gerber/tests/panelize/expects/dxf_save_line.txt
index c3d73d4..c3d73d4 100644
--- a/tests/expects/dxf_save_line.txt
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_line.txt
diff --git a/tests/expects/dxf_save_mousebites.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.gtl
index 64cc6d8..64cc6d8 100644
--- a/tests/expects/dxf_save_mousebites.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.gtl
diff --git a/tests/expects/dxf_save_mousebites.txt b/gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.txt
index 4a64514..4a64514 100644
--- a/tests/expects/dxf_save_mousebites.txt
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_save_mousebites.txt
diff --git a/tests/expects/dxf_to_inch.gtl b/gerbonara/gerber/tests/panelize/expects/dxf_to_inch.gtl
index f838214..f838214 100644
--- a/tests/expects/dxf_to_inch.gtl
+++ b/gerbonara/gerber/tests/panelize/expects/dxf_to_inch.gtl
diff --git a/tests/expects/excellon_offset.txt b/gerbonara/gerber/tests/panelize/expects/excellon_offset.txt
index 9a0b430..9a0b430 100644
--- a/tests/expects/excellon_offset.txt
+++ b/gerbonara/gerber/tests/panelize/expects/excellon_offset.txt
diff --git a/tests/expects/excellon_rotate.txt b/gerbonara/gerber/tests/panelize/expects/excellon_rotate.txt
index f33dcfd..f33dcfd 100644
--- a/tests/expects/excellon_rotate.txt
+++ b/gerbonara/gerber/tests/panelize/expects/excellon_rotate.txt
diff --git a/tests/expects/excellon_save.txt b/gerbonara/gerber/tests/panelize/expects/excellon_save.txt
index 18fdcc4..18fdcc4 100644
--- a/tests/expects/excellon_save.txt
+++ b/gerbonara/gerber/tests/panelize/expects/excellon_save.txt
diff --git a/tests/expects/excellon_to_inch.txt b/gerbonara/gerber/tests/panelize/expects/excellon_to_inch.txt
index 6af5494..6af5494 100644
--- a/tests/expects/excellon_to_inch.txt
+++ b/gerbonara/gerber/tests/panelize/expects/excellon_to_inch.txt
diff --git a/tests/expects/excellon_to_metric.txt b/gerbonara/gerber/tests/panelize/expects/excellon_to_metric.txt
index 20f698e..20f698e 100644
--- a/tests/expects/excellon_to_metric.txt
+++ b/gerbonara/gerber/tests/panelize/expects/excellon_to_metric.txt
diff --git a/tests/test_am_expression.py b/gerbonara/gerber/tests/panelize/test_am_expression.py
index cf30ab7..bed04a6 100644
--- a/tests/test_am_expression.py
+++ b/gerbonara/gerber/tests/panelize/test_am_expression.py
@@ -4,10 +4,10 @@
# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
import unittest
-from gerbonara.gerber.panelize.am_expression import *
-from gerbonara.gerber.panelize.am_expression import AMOperatorExpression as Op
-from gerbonara.gerber.utils import inch, metric
-from gerbonara.gerber.am_read import read_macro
+from ...panelize.am_expression import *
+from ...panelize.am_expression import AMOperatorExpression as Op
+from ...utils import inch, metric
+from ...am_read import read_macro
class TestAMConstantExpression(unittest.TestCase):
def setUp(self):
@@ -204,5 +204,3 @@ class TestEvalMacro(unittest.TestCase):
gerber += '${0}={1}*'.format(-number, expressions[0].to_gerber())
return gerber
-if __name__ == '__main__':
- unittest.main()
diff --git a/gerbonara/gerber/tests/panelize/test_dxf.py b/gerbonara/gerber/tests/panelize/test_dxf.py
new file mode 100644
index 0000000..dfd59d2
--- /dev/null
+++ b/gerbonara/gerber/tests/panelize/test_dxf.py
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+import os
+import tempfile
+from pathlib import Path
+from contextlib import contextmanager
+import unittest
+from ... import panelize
+from ...utils import inch, metric
+
+
+class TestExcellon(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ here = Path(__file__).parent
+ cls.EXPECTSDIR = here / 'expects'
+
+ cls.METRIC_FILE = here / 'data' / 'ref_dxf_metric.dxf'
+ cls.INCH_FILE = here / 'data' / 'ref_dxf_inch.dxf'
+ cls.COMPLEX_FILE = here / 'data' / 'ref_dxf_complex.dxf'
+
+ @contextmanager
+ def _check_result(self, reference_fn):
+ with tempfile.NamedTemporaryFile('rb') as tmp_out:
+ yield tmp_out.name
+
+ actual = tmp_out.read()
+ expected = (self.EXPECTSDIR / reference_fn).read_bytes()
+ self.assertEqual(actual, expected)
+
+ def test_save_line(self):
+ with self._check_result('dxf_save_line.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_LINE
+ dxf.width = 0.2
+ dxf.write(outfile)
+
+ def test_save_fill(self):
+ with self._check_result('dxf_save_fill.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_FILL
+ dxf.write(outfile)
+
+ def test_save_fill_simple(self):
+ with self._check_result('dxf_save_fill_simple.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_FILL
+ dxf.fill_mode = dxf.FM_SIMPLE
+ dxf.write(outfile)
+
+ def test_save_mousebites(self):
+ with self._check_result('dxf_save_mousebites.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_MOUSE_BITES
+ dxf.width = 0.5
+ dxf.pitch = 1.4
+ dxf.write(outfile)
+
+ def test_save_excellon(self):
+ with self._check_result('dxf_save_line.txt') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_LINE
+ dxf.format = (3,3)
+ dxf.width = 0.2
+ dxf.write(outfile, filetype=dxf.FT_EXCELLON)
+
+ def test_save_excellon_mousebites(self):
+ with self._check_result('dxf_save_mousebites.txt') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.draw_mode = dxf.DM_MOUSE_BITES
+ dxf.format = (3, 3)
+ dxf.width = 0.5
+ dxf.pitch = 1.4
+ dxf.write(outfile, filetype=dxf.FT_EXCELLON)
+
+ def test_to_inch(self):
+ with self._check_result('dxf_to_inch.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.to_inch()
+ dxf.format = (2, 5)
+ dxf.write(outfile)
+
+ def _test_to_metric(self):
+ with self._check_result('dxf_to_metric.gtl') as outfile:
+ dxf = panelize.read(self.INCH_FILE)
+ dxf.to_metric()
+ dxf.format = (3, 5)
+ dxf.write(outfile)
+
+ def test_offset(self):
+ with self._check_result('dxf_offset.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.offset(11, 5)
+ dxf.write(outfile)
+
+ def test_rotate(self):
+ with self._check_result('dxf_rotate.gtl') as outfile:
+ dxf = panelize.read(self.METRIC_FILE)
+ dxf.rotate(20, (10, 10))
+ dxf.write(outfile)
+
+ def test_rectangle_metric(self):
+ with self._check_result('dxf_rectangle_metric.gtl') as outfile:
+ dxf = panelize.DxfFile.rectangle(width=10, height=10, units='metric')
+ dxf.write(outfile)
+
+ def test_rectangle_inch(self):
+ with self._check_result('dxf_rectangle_inch.gtl') as outfile:
+ dxf = panelize.DxfFile.rectangle(width=inch(10), height=inch(10), units='inch')
+ dxf.write(outfile)
+
+ def test_complex_fill(self):
+ with self._check_result('dxf_complex_fill.gtl') as outfile:
+ dxf = panelize.read(self.COMPLEX_FILE)
+ dxf.draw_mode = dxf.DM_FILL
+ dxf.write(outfile)
+
+ def test_complex_fill_flip(self):
+ with self._check_result('dxf_complex_fill_flip.gtl') as outfile:
+ ctx = panelize.GerberComposition()
+ base = panelize.rectangle(width=100, height=100, left=0, bottom=0, units='metric')
+ base.draw_mode = base.DM_FILL
+ ctx.merge(base)
+ dxf = panelize.read(self.COMPLEX_FILE)
+ dxf.negate_polarity()
+ dxf.draw_mode = dxf.DM_FILL
+ ctx.merge(dxf)
+ ctx.dump(outfile)
+
diff --git a/gerbonara/gerber/tests/panelize/test_excellon.py b/gerbonara/gerber/tests/panelize/test_excellon.py
new file mode 100644
index 0000000..1d255cc
--- /dev/null
+++ b/gerbonara/gerber/tests/panelize/test_excellon.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+import os
+import tempfile
+from pathlib import Path
+from contextlib import contextmanager
+import unittest
+from ... import panelize
+
+class TestExcellon(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ here = Path(__file__).parent
+ cls.EXPECTSDIR = here / 'expects'
+ cls.METRIC_FILE = here / 'data' / 'ref_drill_metric.txt'
+ cls.INCH_FILE = here / 'data' / 'ref_drill_inch.txt'
+
+ @contextmanager
+ def _check_result(self, reference_fn):
+ with tempfile.NamedTemporaryFile('rb') as tmp_out:
+ yield tmp_out.name
+
+ actual = tmp_out.read()
+ expected = (self.EXPECTSDIR / reference_fn).read_bytes()
+ self.assertEqual(actual, expected)
+
+ def test_save(self):
+ with self._check_result('excellon_save.txt') as outfile:
+ drill = panelize.read(self.METRIC_FILE)
+ drill.write(outfile)
+
+ def test_to_inch(self):
+ with self._check_result('excellon_to_inch.txt') as outfile:
+ drill = panelize.read(self.METRIC_FILE)
+ drill.to_inch()
+ drill.format = (2, 4)
+ drill.write(outfile)
+
+ def test_to_metric(self):
+ with self._check_result('excellon_to_metric.txt') as outfile:
+ drill = panelize.read(self.INCH_FILE)
+ drill.to_metric()
+ drill.format = (3, 3)
+ drill.write(outfile)
+
+ def test_offset(self):
+ with self._check_result('excellon_offset.txt') as outfile:
+ drill = panelize.read(self.METRIC_FILE)
+ drill.offset(11, 5)
+ drill.write(outfile)
+
+ def test_rotate(self):
+ with self._check_result('excellon_rotate.txt') as outfile:
+ drill = panelize.read(self.METRIC_FILE)
+ drill.rotate(20, (10, 10))
+ drill.write(outfile)
+
diff --git a/gerbonara/gerber/tests/panelize/test_rs274x.py b/gerbonara/gerber/tests/panelize/test_rs274x.py
new file mode 100644
index 0000000..85748a3
--- /dev/null
+++ b/gerbonara/gerber/tests/panelize/test_rs274x.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+import os
+import tempfile
+from pathlib import Path
+from contextlib import contextmanager
+import unittest
+from ... import panelize
+
+class TestRs274x(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ here = Path(__file__).parent
+ cls.EXPECTSDIR = here / 'expects'
+ cls.METRIC_FILE = here / 'data' / 'ref_gerber_metric.gtl'
+ cls.INCH_FILE = here / 'data' / 'ref_gerber_inch.gtl'
+ cls.SQ_FILE = here / 'data' / 'ref_gerber_single_quadrant.gtl'
+
+ @contextmanager
+ def _check_result(self, reference_fn):
+ with tempfile.NamedTemporaryFile('rb') as tmp_out:
+ yield tmp_out.name
+
+ actual = tmp_out.read()
+ expected = (self.EXPECTSDIR / reference_fn).read_bytes()
+ self.assertEqual(actual, expected)
+
+ def test_save(self):
+ with self._check_result('RS2724x_save.gtl') as outfile:
+ gerber = panelize.read(self.METRIC_FILE)
+ gerber.write(outfile)
+
+ def test_to_inch(self):
+ with self._check_result('RS2724x_to_inch.gtl') as outfile:
+ gerber = panelize.read(self.METRIC_FILE)
+ gerber.to_inch()
+ gerber.format = (2,5)
+ gerber.write(outfile)
+
+ def test_to_metric(self):
+ with self._check_result('RS2724x_to_metric.gtl') as outfile:
+ gerber = panelize.read(self.INCH_FILE)
+ gerber.to_metric()
+ gerber.format = (3, 4)
+ gerber.write(outfile)
+
+ def test_offset(self):
+ with self._check_result('RS2724x_offset.gtl') as outfile:
+ gerber = panelize.read(self.METRIC_FILE)
+ gerber.offset(11, 5)
+ gerber.write(outfile)
+
+ def test_rotate(self):
+ with self._check_result('RS2724x_rotate.gtl') as outfile:
+ gerber = panelize.read(self.METRIC_FILE)
+ gerber.rotate(20, (10,10))
+ gerber.write(outfile)
+
+ def test_single_quadrant(self):
+ with self._check_result('RS2724x_single_quadrant.gtl') as outfile:
+ gerber = panelize.read(self.SQ_FILE)
+ gerber.write(outfile)
+
diff --git a/tests/test_utility.py b/gerbonara/gerber/tests/panelize/test_utility.py
index d7a4101..b32af8b 100644
--- a/tests/test_utility.py
+++ b/gerbonara/gerber/tests/panelize/test_utility.py
@@ -5,7 +5,7 @@
import unittest
-from gerbonara.gerber.panelize.utility import *
+from ...panelize.utility import *
from math import sqrt
class TestUtility(unittest.TestCase):
@@ -61,5 +61,3 @@ class TestUtility(unittest.TestCase):
self.assertFalse(is_equal_point(p1, p0, 0.001))
self.assertFalse(is_equal_point(p1, p0))
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_dxf.py b/tests/test_dxf.py
deleted file mode 100644
index e138320..0000000
--- a/tests/test_dxf.py
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
-
-import os
-import unittest
-from gerbonara.gerber import panelize
-from gerbonara.gerber.utils import inch, metric
-
-
-class TestExcellon(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- os.chdir(os.path.dirname(__file__))
- cls.INDIR = 'data'
- cls.OUTDIR = 'outputs'
- cls.EXPECTSDIR = 'expects'
- cls.OUTPREFIX = 'dxf_'
- cls.METRIC_FILE = os.path.join(cls.INDIR, 'ref_dxf_metric.dxf')
- cls.INCH_FILE = os.path.join(cls.INDIR, 'ref_dxf_inch.dxf')
- cls.COMPLEX_FILE = os.path.join(cls.INDIR, 'ref_dxf_complex.dxf')
- try:
- os.mkdir(cls.OUTDIR)
- except FileExistsError:
- pass
-
- def _checkResult(self, file):
- with open(file, 'r') as f:
- data = f.read()
- with open(os.path.join(self.EXPECTSDIR, os.path.basename(file)), 'r') as f:
- expect = f.read()
- self.assertEqual(data, expect)
-
- def test_save_line(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_line.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_LINE
- dxf.width = 0.2
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_save_fill(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_fill.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_FILL
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_save_fill_simple(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_fill_simple.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_FILL
- dxf.fill_mode = dxf.FM_SIMPLE
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_save_mousebites(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_mousebites.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_MOUSE_BITES
- dxf.width = 0.5
- dxf.pitch = 1.4
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_save_excellon(self):
- outfile = os.path.join(
- self.OUTDIR, self.OUTPREFIX + 'save_line.txt')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_LINE
- dxf.format = (3,3)
- dxf.width = 0.2
- dxf.write(outfile, filetype=dxf.FT_EXCELLON)
- self._checkResult(outfile)
-
- def test_save_excellon_mousebites(self):
- outfile = os.path.join(
- self.OUTDIR, self.OUTPREFIX + 'save_mousebites.txt')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.draw_mode = dxf.DM_MOUSE_BITES
- dxf.format = (3, 3)
- dxf.width = 0.5
- dxf.pitch = 1.4
- dxf.write(outfile, filetype=dxf.FT_EXCELLON)
- self._checkResult(outfile)
-
- def test_to_inch(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_inch.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.to_inch()
- dxf.format = (2, 5)
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def _test_to_metric(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_metric.gtl')
- dxf = panelize.read(self.INCH_FILE)
- dxf.to_metric()
- dxf.format = (3, 5)
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_offset(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'offset.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.offset(11, 5)
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_rotate(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rotate.gtl')
- dxf = panelize.read(self.METRIC_FILE)
- dxf.rotate(20, (10, 10))
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_rectangle_metric(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rectangle_metric.gtl')
- dxf = panelize.DxfFile.rectangle(width=10, height=10, units='metric')
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_rectangle_inch(self):
- outfile = os.path.join(
- self.OUTDIR, self.OUTPREFIX + 'rectangle_inch.gtl')
- dxf = panelize.DxfFile.rectangle(width=inch(10), height=inch(10), units='inch')
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_complex_fill(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'complex_fill.gtl')
- dxf = panelize.read(self.COMPLEX_FILE)
- dxf.draw_mode = dxf.DM_FILL
- dxf.write(outfile)
- self._checkResult(outfile)
-
- def test_complex_fill_flip(self):
- outfile = os.path.join(
- self.OUTDIR, self.OUTPREFIX + 'complex_fill_flip.gtl')
- ctx = panelize.GerberComposition()
- base = panelize.rectangle(width=100, height=100, left=0, bottom=0, units='metric')
- base.draw_mode = base.DM_FILL
- ctx.merge(base)
- dxf = panelize.read(self.COMPLEX_FILE)
- dxf.negate_polarity()
- dxf.draw_mode = dxf.DM_FILL
- ctx.merge(dxf)
- ctx.dump(outfile)
- self._checkResult(outfile)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_excellon.py b/tests/test_excellon.py
deleted file mode 100644
index 4aa6dcf..0000000
--- a/tests/test_excellon.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
-
-import os
-import unittest
-from gerbonara.gerber import panelize
-
-
-class TestExcellon(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- os.chdir(os.path.dirname(__file__))
- cls.INDIR = 'data'
- cls.OUTDIR = 'outputs'
- cls.EXPECTSDIR = 'expects'
- cls.OUTPREFIX = 'excellon_'
- cls.METRIC_FILE = os.path.join(cls.INDIR, 'ref_drill_metric.txt')
- cls.INCH_FILE = os.path.join(cls.INDIR, 'ref_drill_inch.txt')
- try:
- os.mkdir(cls.OUTDIR)
- except FileExistsError:
- pass
-
- def _checkResult(self, file):
- with open(file, 'r') as f:
- data = f.read()
- with open(os.path.join(self.EXPECTSDIR, os.path.basename(file)), 'r') as f:
- expect = f.read()
- self.assertEqual(data, expect)
- pass
-
- def test_save(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save.txt')
- drill = panelize.read(self.METRIC_FILE)
- drill.write(outfile)
- self._checkResult(outfile)
-
- def test_to_inch(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_inch.txt')
- drill = panelize.read(self.METRIC_FILE)
- drill.to_inch()
- drill.format = (2, 4)
- drill.write(outfile)
- self._checkResult(outfile)
-
- def test_to_metric(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_metric.txt')
- drill = panelize.read(self.INCH_FILE)
- drill.to_metric()
- drill.format = (3, 3)
- drill.write(outfile)
- self._checkResult(outfile)
-
- def test_offset(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'offset.txt')
- drill = panelize.read(self.METRIC_FILE)
- drill.offset(11, 5)
- drill.write(outfile)
- self._checkResult(outfile)
-
- def test_rotate(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rotate.txt')
- drill = panelize.read(self.METRIC_FILE)
- drill.rotate(20, (10, 10))
- drill.write(outfile)
- self._checkResult(outfile)
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_rs274x.py b/tests/test_rs274x.py
deleted file mode 100644
index 1a1475a..0000000
--- a/tests/test_rs274x.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
-
-import os
-import unittest
-from gerbonara.gerber import panelize
-
-class TestRs274x(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- os.chdir(os.path.dirname(__file__))
- cls.INDIR = 'data'
- cls.OUTDIR = 'outputs'
- cls.EXPECTSDIR = 'expects'
- cls.OUTPREFIX = 'RS2724x_'
- cls.METRIC_FILE = os.path.join(cls.INDIR, 'ref_gerber_metric.gtl')
- cls.INCH_FILE = os.path.join(cls.INDIR, 'ref_gerber_inch.gtl')
- cls.SQ_FILE = os.path.join(cls.INDIR, 'ref_gerber_single_quadrant.gtl')
- try:
- os.mkdir(cls.OUTDIR)
- except FileExistsError:
- pass
-
- def _checkResult(self, file):
- with open(file, 'r') as f:
- data = f.read()
- with open(os.path.join(self.EXPECTSDIR, os.path.basename(file)), 'r') as f:
- expect = f.read()
- self.assertEqual(data, expect)
-
- def test_save(self):
- outfile=os.path.join(self.OUTDIR, self.OUTPREFIX + 'save.gtl')
- gerber = panelize.read(self.METRIC_FILE)
- gerber.write(outfile)
- self._checkResult(outfile)
-
- def test_to_inch(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_inch.gtl')
- gerber = panelize.read(self.METRIC_FILE)
- gerber.to_inch()
- gerber.format = (2,5)
- gerber.write(outfile)
- self._checkResult(outfile)
-
- def test_to_metric(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_metric.gtl')
- gerber = panelize.read(self.INCH_FILE)
- gerber.to_metric()
- gerber.format = (3, 4)
- gerber.write(outfile)
- self._checkResult(outfile)
-
- def test_offset(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'offset.gtl')
- gerber = panelize.read(self.METRIC_FILE)
- gerber.offset(11, 5)
- gerber.write(outfile)
- self._checkResult(outfile)
-
- def test_rotate(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rotate.gtl')
- gerber = panelize.read(self.METRIC_FILE)
- gerber.rotate(20, (10,10))
- gerber.write(outfile)
- self._checkResult(outfile)
-
- def test_single_quadrant(self):
- outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'single_quadrant.gtl')
- gerber = panelize.read(self.SQ_FILE)
- gerber.write(outfile)
- self._checkResult(outfile)
-
-if __name__ == '__main__':
- unittest.main()