From 1750c3c60aeffc813dad8191ceabcdb90dd2e0a6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 10 Oct 2014 13:07:54 -0400 Subject: Add tests --- gerber/gerber_statements.py | 12 ++- gerber/tests/test_gerber_statements.py | 155 +++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 3 deletions(-) diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 2caced5..9072b58 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -284,9 +284,9 @@ class LPParamStmt(ParamStmt): ParamStmt.__init__(self, param) self.lp = lp - def to_gerber(self, settings): - lp = 'C' if self.lp == 'clear' else 'dark' - return '%LP{0}*%'.format(self.lp) + def to_gerber(self): + lp = 'C' if self.lp == 'clear' else 'D' + return '%LP{0}*%'.format(lp) def __str__(self): return '' % self.lp @@ -593,6 +593,7 @@ class ApertureStmt(Statement): class CommentStmt(Statement): """ Comment Statment """ + def __init__(self, comment): Statement.__init__(self, "COMMENT") self.comment = comment @@ -616,6 +617,7 @@ class EofStmt(Statement): def __str__(self): return '' + class QuadrantModeStmt(Statement): @classmethod @@ -638,6 +640,7 @@ class QuadrantModeStmt(Statement): def to_gerber(self): return 'G74*' if self.mode == 'single-quadrant' else 'G75*' + class RegionModeStmt(Statement): @classmethod @@ -664,3 +667,6 @@ class UnknownStmt(Statement): def __init__(self, line): Statement.__init__(self, "UNKNOWN") self.line = line + + def to_gerber(self): + return self.line 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) + -- cgit