summaryrefslogtreecommitdiff
path: root/gerber/tests
diff options
context:
space:
mode:
Diffstat (limited to 'gerber/tests')
-rw-r--r--gerber/tests/test_gerber_statements.py155
1 files changed, 155 insertions, 0 deletions
diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py
index 7c01130..9e73fd4 100644
--- a/gerber/tests/test_gerber_statements.py
+++ b/gerber/tests/test_gerber_statements.py
@@ -102,3 +102,158 @@ def test_OFParamStmt_dump():
stmt = {'param': 'OF', 'a': '0.1234567', 'b': '0.1234567'}
of = OFParamStmt.from_dict(stmt)
assert_equal(of.to_gerber(), '%OFA0.123456B0.123456*%')
+
+
+def test_LPParamStmt_factory():
+ """ Test LPParamStmt factory correctly handles parameters
+ """
+ stmt = {'param': 'LP', 'lp': 'C'}
+ lp = LPParamStmt.from_dict(stmt)
+ assert_equal(lp.lp, 'clear')
+
+ stmt = {'param': 'LP', 'lp': 'D'}
+ lp = LPParamStmt.from_dict(stmt)
+ assert_equal(lp.lp, 'dark')
+
+def test_LPParamStmt_dump():
+ """ Test LPParamStmt to_gerber()
+ """
+ stmt = {'param': 'LP', 'lp': 'C'}
+ lp = LPParamStmt.from_dict(stmt)
+ assert_equal(lp.to_gerber(), '%LPC*%')
+
+ stmt = {'param': 'LP', 'lp': 'D'}
+ lp = LPParamStmt.from_dict(stmt)
+ assert_equal(lp.to_gerber(), '%LPD*%')
+
+
+def test_INParamStmt_factory():
+ """ Test INParamStmt factory correctly handles parameters
+ """
+ stmt = {'param': 'IN', 'name': 'test'}
+ inp = INParamStmt.from_dict(stmt)
+ assert_equal(inp.name, 'test')
+
+def test_INParamStmt_dump():
+ """ Test INParamStmt to_gerber()
+ """
+ stmt = {'param': 'IN', 'name': 'test'}
+ inp = INParamStmt.from_dict(stmt)
+ assert_equal(inp.to_gerber(), '%INtest*%')
+
+
+def test_LNParamStmt_factory():
+ """ Test LNParamStmt factory correctly handles parameters
+ """
+ stmt = {'param': 'LN', 'name': 'test'}
+ lnp = LNParamStmt.from_dict(stmt)
+ assert_equal(lnp.name, 'test')
+
+def test_LNParamStmt_dump():
+ """ Test LNParamStmt to_gerber()
+ """
+ stmt = {'param': 'LN', 'name': 'test'}
+ lnp = LNParamStmt.from_dict(stmt)
+ assert_equal(lnp.to_gerber(), '%LNtest*%')
+
+def test_comment_stmt():
+ """ Test comment statement
+ """
+ stmt = CommentStmt('A comment')
+ assert_equal(stmt.type, 'COMMENT')
+ assert_equal(stmt.comment, 'A comment')
+
+def test_comment_stmt_dump():
+ """ Test CommentStmt to_gerber()
+ """
+ stmt = CommentStmt('A comment')
+ assert_equal(stmt.to_gerber(), 'G04A comment*')
+
+
+def test_eofstmt():
+ """ Test EofStmt
+ """
+ stmt = EofStmt()
+ assert_equal(stmt.type, 'EOF')
+
+def test_eofstmt_dump():
+ """ Test EofStmt to_gerber()
+ """
+ stmt = EofStmt()
+ assert_equal(stmt.to_gerber(), 'M02*')
+
+
+def test_quadmodestmt_factory():
+ """ Test QuadrantModeStmt.from_gerber()
+ """
+ line = 'G74*'
+ stmt = QuadrantModeStmt.from_gerber(line)
+ assert_equal(stmt.type, 'QuadrantMode')
+ assert_equal(stmt.mode, 'single-quadrant')
+
+ line = 'G75*'
+ stmt = QuadrantModeStmt.from_gerber(line)
+ assert_equal(stmt.mode, 'multi-quadrant')
+
+def test_quadmodestmt_validation():
+ """ Test QuadrantModeStmt input validation
+ """
+ line = 'G76*'
+ assert_raises(ValueError, QuadrantModeStmt.from_gerber, line)
+ assert_raises(ValueError, QuadrantModeStmt, 'quadrant-ful')
+
+
+def test_quadmodestmt_dump():
+ """ Test QuadrantModeStmt.to_gerber()
+ """
+ for line in ('G74*', 'G75*',):
+ stmt = QuadrantModeStmt.from_gerber(line)
+ assert_equal(stmt.to_gerber(), line)
+
+
+def test_regionmodestmt_factory():
+ """ Test RegionModeStmt.from_gerber()
+ """
+ line = 'G36*'
+ stmt = RegionModeStmt.from_gerber(line)
+ assert_equal(stmt.type, 'RegionMode')
+ assert_equal(stmt.mode, 'on')
+
+ line = 'G37*'
+ stmt = RegionModeStmt.from_gerber(line)
+ assert_equal(stmt.mode, 'off')
+
+
+def test_regionmodestmt_validation():
+ """ Test RegionModeStmt input validation
+ """
+ line = 'G38*'
+ assert_raises(ValueError, RegionModeStmt.from_gerber, line)
+ assert_raises(ValueError, RegionModeStmt, 'off-ish')
+
+
+def test_regionmodestmt_dump():
+ """ Test RegionModeStmt.to_gerber()
+ """
+ for line in ('G36*', 'G37*',):
+ stmt = RegionModeStmt.from_gerber(line)
+ assert_equal(stmt.to_gerber(), line)
+
+
+def test_unknownstmt():
+ """ Test UnknownStmt
+ """
+ line = 'G696969*'
+ stmt = UnknownStmt(line)
+ assert_equal(stmt.type, 'UNKNOWN')
+ assert_equal(stmt.line, line)
+
+
+def test_unknownstmt_dump():
+ """ Test UnknownStmt.to_gerber()
+ """
+ lines = ('G696969*', 'M03*',)
+ for line in lines:
+ stmt = UnknownStmt(line)
+ assert_equal(stmt.to_gerber(), line)
+