summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/excellon_statements.py16
-rw-r--r--gerber/tests/test_excellon_statements.py119
2 files changed, 128 insertions, 7 deletions
diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py
index 13f763e..5eba12c 100644
--- a/gerber/excellon_statements.py
+++ b/gerber/excellon_statements.py
@@ -331,10 +331,10 @@ class IncrementalModeStmt(ExcellonStatement):
def __init__(self, mode='off'):
if mode.lower() not in ['on', 'off']:
raise ValueError('Mode may be "on" or "off"')
- self.mode = 'off'
+ self.mode = mode
def to_excellon(self):
- return 'ICI,%s' % 'OFF' if self.mode == 'off' else 'ON'
+ return 'ICI,%s' % ('OFF' if self.mode == 'off' else 'ON')
class VersionStmt(ExcellonStatement):
@@ -361,14 +361,14 @@ class FormatStmt(ExcellonStatement):
fmt = int(line.split(',')[1])
return cls(fmt)
- def __init__(self, nformat=1):
- nformat = int(nformat)
- if nformat not in [1, 2]:
+ def __init__(self, format=1):
+ format = int(format)
+ if format not in [1, 2]:
raise ValueError('Valid formats are 1 or 2')
- self.nformat = nformat
+ self.format = format
def to_excellon(self):
- return 'FMAT,%d' % self.n
+ return 'FMAT,%d' % self.format
class LinkToolStmt(ExcellonStatement):
@@ -389,6 +389,8 @@ class MeasuringModeStmt(ExcellonStatement):
@classmethod
def from_excellon(cls, line):
+ if not ('M71' in line or 'M72' in line):
+ raise ValueError('Not a measuring mode statement')
return cls('inch') if 'M72' in line else cls('metric')
def __init__(self, units='inch'):
diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py
index c728443..4fa2b35 100644
--- a/gerber/tests/test_excellon_statements.py
+++ b/gerber/tests/test_excellon_statements.py
@@ -108,3 +108,122 @@ def test_commentstmt_dump():
stmt = CommentStmt.from_excellon(line)
assert_equal(stmt.to_excellon(), line)
+
+def test_unitstmt_factory():
+ line = 'INCH,LZ'
+ stmt = UnitStmt.from_excellon(line)
+ assert_equal(stmt.units, 'inch')
+ assert_equal(stmt.zero_suppression, 'trailing')
+
+ line = 'METRIC,TZ'
+ stmt = UnitStmt.from_excellon(line)
+ assert_equal(stmt.units, 'metric')
+ assert_equal(stmt.zero_suppression, 'leading')
+
+
+def test_unitstmt_dump():
+ lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ]
+ for line in lines:
+ stmt = UnitStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+
+def test_incrementalmode_factory():
+ line = 'ICI,ON'
+ stmt = IncrementalModeStmt.from_excellon(line)
+ assert_equal(stmt.mode, 'on')
+
+ line = 'ICI,OFF'
+ stmt = IncrementalModeStmt.from_excellon(line)
+ assert_equal(stmt.mode, 'off')
+
+
+def test_incrementalmode_dump():
+ lines = ['ICI,ON', 'ICI,OFF', ]
+ for line in lines:
+ stmt = IncrementalModeStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+
+def test_incrementalmode_validation():
+ assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH')
+
+
+def test_versionstmt_factory():
+ line = 'VER,1'
+ stmt = VersionStmt.from_excellon(line)
+ assert_equal(stmt.version, 1)
+
+ line = 'VER,2'
+ stmt = VersionStmt.from_excellon(line)
+ assert_equal(stmt.version, 2)
+
+
+def test_versionstmt_dump():
+ lines = ['VER,1', 'VER,2', ]
+ for line in lines:
+ stmt = VersionStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+def test_versionstmt_validation():
+ assert_raises(ValueError, VersionStmt, 3)
+
+
+def test_formatstmt_factory():
+ line = 'FMAT,1'
+ stmt = FormatStmt.from_excellon(line)
+ assert_equal(stmt.format, 1)
+
+ line = 'FMAT,2'
+ stmt = FormatStmt.from_excellon(line)
+ assert_equal(stmt.format, 2)
+
+
+def test_formatstmt_dump():
+ lines = ['FMAT,1', 'FMAT,2', ]
+ for line in lines:
+ stmt = FormatStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+
+def test_formatstmt_validation():
+ assert_raises(ValueError, FormatStmt, 3)
+
+
+def test_linktoolstmt_factory():
+ line = '1/2/3/4'
+ stmt = LinkToolStmt.from_excellon(line)
+ assert_equal(stmt.linked_tools, [1, 2, 3, 4])
+
+ line = '01/02/03/04'
+ stmt = LinkToolStmt.from_excellon(line)
+ assert_equal(stmt.linked_tools, [1, 2, 3, 4])
+
+
+def test_linktoolstmt_dump():
+ lines = ['1/2/3/4', '5/6/7', ]
+ for line in lines:
+ stmt = LinkToolStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+
+def test_measuringmodestmt_factory():
+ line = 'M72'
+ stmt = MeasuringModeStmt.from_excellon(line)
+ assert_equal(stmt.units, 'inch')
+
+ line = 'M71'
+ stmt = MeasuringModeStmt.from_excellon(line)
+ assert_equal(stmt.units, 'metric')
+
+
+def test_measuringmodestmt_dump():
+ lines = ['M71', 'M72', ]
+ for line in lines:
+ stmt = MeasuringModeStmt.from_excellon(line)
+ assert_equal(stmt.to_excellon(), line)
+
+
+def test_measuringmodestmt_validation():
+ assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70')
+ assert_raises(ValueError, MeasuringModeStmt, 'millimeters')