From f8449ad2b60b8a715d0867325e257a8297193b49 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 30 Sep 2014 23:42:02 -0400 Subject: tests update --- gerber/tests/test_cnc.py | 50 +++++++++++++++++++++++ gerber/tests/test_statements.py | 87 +++++++++++++++++++++++++++++++++++++++++ gerber/tests/tests.py | 18 +++++++++ 3 files changed, 155 insertions(+) create mode 100644 gerber/tests/test_cnc.py create mode 100644 gerber/tests/test_statements.py create mode 100644 gerber/tests/tests.py (limited to 'gerber/tests') diff --git a/gerber/tests/test_cnc.py b/gerber/tests/test_cnc.py new file mode 100644 index 0000000..ace047e --- /dev/null +++ b/gerber/tests/test_cnc.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from ..cnc import CncFile, FileSettings +from tests import * + + +def test_smoke_filesettings(): + """ Smoke test FileSettings class + """ + fs = FileSettings() + + +def test_filesettings_defaults(): + """ Test FileSettings default values + """ + fs = FileSettings() + assert_equal(fs.format, (2, 5)) + assert_equal(fs.notation, 'absolute') + assert_equal(fs.zero_suppression, 'trailing') + assert_equal(fs.units, 'inch') + + +def test_filesettings_dict(): + """ Test FileSettings Dict + """ + fs = FileSettings() + assert_equal(fs['format'], (2, 5)) + assert_equal(fs['notation'], 'absolute') + assert_equal(fs['zero_suppression'], 'trailing') + assert_equal(fs['units'], 'inch') + + +def test_filesettings_assign(): + """ Test FileSettings attribute assignment + """ + fs = FileSettings() + fs.units = 'test' + fs.notation = 'test' + fs.zero_suppression = 'test' + fs.format = 'test' + assert_equal(fs.units, 'test') + assert_equal(fs.notation, 'test') + assert_equal(fs.zero_suppression, 'test') + assert_equal(fs.format, 'test') + + def test_smoke_cncfile(): + pass diff --git a/gerber/tests/test_statements.py b/gerber/tests/test_statements.py new file mode 100644 index 0000000..47fbb48 --- /dev/null +++ b/gerber/tests/test_statements.py @@ -0,0 +1,87 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from .tests import * +from ..statements import * + + +def test_FSParamStmt_factory(): + """ Test FSParamStruct factory correctly handles parameters + """ + stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} + fs = FSParamStmt.from_dict(stmt) + assert_equal(fs.param, 'FS') + assert_equal(fs.zero_suppression, 'leading') + assert_equal(fs.notation, 'absolute') + assert_equal(fs.format, (2, 7)) + + stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '27'} + fs = FSParamStmt.from_dict(stmt) + assert_equal(fs.param, 'FS') + assert_equal(fs.zero_suppression, 'trailing') + assert_equal(fs.notation, 'incremental') + assert_equal(fs.format, (2, 7)) + + +def test_FSParamStmt_dump(): + """ Test FSParamStmt to_gerber() + """ + stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} + fs = FSParamStmt.from_dict(stmt) + assert_equal(fs.to_gerber(), '%FSLAX27Y27*%') + + stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '25'} + fs = FSParamStmt.from_dict(stmt) + assert_equal(fs.to_gerber(), '%FSTIX25Y25*%') + + +def test_MOParamStmt_factory(): + """ Test MOParamStruct factory correctly handles parameters + """ + stmt = {'param': 'MO', 'mo': 'IN'} + mo = MOParamStmt.from_dict(stmt) + assert_equal(mo.param, 'MO') + assert_equal(mo.mode, 'inch') + + stmt = {'param': 'MO', 'mo': 'MM'} + mo = MOParamStmt.from_dict(stmt) + assert_equal(mo.param, 'MO') + assert_equal(mo.mode, 'metric') + + +def test_MOParamStmt_dump(): + """ Test MOParamStmt to_gerber() + """ + stmt = {'param': 'MO', 'mo': 'IN'} + mo = MOParamStmt.from_dict(stmt) + assert_equal(mo.to_gerber(), '%MOIN*%') + + stmt = {'param': 'MO', 'mo': 'MM'} + mo = MOParamStmt.from_dict(stmt) + assert_equal(mo.to_gerber(), '%MOMM*%') + + +def test_IPParamStmt_factory(): + """ Test IPParamStruct factory correctly handles parameters + """ + stmt = {'param': 'IP', 'ip': 'POS'} + ip = IPParamStmt.from_dict(stmt) + assert_equal(ip.ip, 'positive') + + stmt = {'param': 'IP', 'ip': 'NEG'} + ip = IPParamStmt.from_dict(stmt) + assert_equal(ip.ip, 'negative') + + +def test_IPParamStmt_dump(): + """ Test IPParamStmt to_gerber() + """ + stmt = {'param': 'IP', 'ip': 'POS'} + ip = IPParamStmt.from_dict(stmt) + assert_equal(ip.to_gerber(), '%IPPOS*%') + + stmt = {'param': 'IP', 'ip': 'NEG'} + ip = IPParamStmt.from_dict(stmt) + assert_equal(ip.to_gerber(), '%IPNEG*%') diff --git a/gerber/tests/tests.py b/gerber/tests/tests.py new file mode 100644 index 0000000..29b7899 --- /dev/null +++ b/gerber/tests/tests.py @@ -0,0 +1,18 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from nose.tools import assert_in +from nose.tools import assert_not_in +from nose.tools import assert_equal +from nose.tools import assert_not_equal +from nose.tools import assert_true +from nose.tools import assert_false +from nose.tools import assert_raises +from nose.tools import raises +from nose import with_setup + +__all__ = ['assert_in', 'assert_not_in', 'assert_equal', 'assert_not_equal', + 'assert_true', 'assert_false', 'assert_raises', 'raises', + 'with_setup' ] -- cgit