summaryrefslogtreecommitdiff
path: root/gerber/tests
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-10-14 15:37:02 -0300
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-10-14 15:37:02 -0300
commit944c8329222b8c1166a4952df0ca553cbec71505 (patch)
treec9b4263852cf6e8a2f4003ac746011424d1edc69 /gerber/tests
parentb81c9d4bf96845ced3495eb158ec3a3c9e4dce3d (diff)
parent10d9028e1fdf7431baee73c7f1474d2134bac5fa (diff)
downloadgerbonara-944c8329222b8c1166a4952df0ca553cbec71505.tar.gz
gerbonara-944c8329222b8c1166a4952df0ca553cbec71505.tar.bz2
gerbonara-944c8329222b8c1166a4952df0ca553cbec71505.zip
Merge pull request #41 from curtacircuitos/read_from_memory
Read from memory
Diffstat (limited to 'gerber/tests')
-rw-r--r--gerber/tests/test_common.py13
-rw-r--r--gerber/tests/test_excellon.py38
2 files changed, 42 insertions, 9 deletions
diff --git a/gerber/tests/test_common.py b/gerber/tests/test_common.py
index 76e3991..0ba4b68 100644
--- a/gerber/tests/test_common.py
+++ b/gerber/tests/test_common.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-from ..common import read
+from ..common import read, loads
from ..excellon import ExcellonFile
from ..rs274x import GerberFile
from .tests import *
@@ -23,9 +23,20 @@ def test_file_type_detection():
assert_true(isinstance(ncdrill, ExcellonFile))
assert_true(isinstance(top_copper, GerberFile))
+
+def test_load_from_string():
+ with open(NCDRILL_FILE, 'r') as f:
+ ncdrill = loads(f.read())
+ with open(TOP_COPPER_FILE, 'r') as f:
+ top_copper = loads(f.read())
+ assert_true(isinstance(ncdrill, ExcellonFile))
+ assert_true(isinstance(top_copper, GerberFile))
+
+
def test_file_type_validation():
""" Test file format validation
"""
assert_raises(TypeError, read, 'LICENSE')
+
diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py
index 006277d..b821649 100644
--- a/gerber/tests/test_excellon.py
+++ b/gerber/tests/test_excellon.py
@@ -11,41 +11,51 @@ from .tests import *
NCDRILL_FILE = os.path.join(os.path.dirname(__file__),
- 'resources/ncdrill.DRD')
+ 'resources/ncdrill.DRD')
def test_format_detection():
""" Test file type detection
"""
- settings = detect_excellon_format(NCDRILL_FILE)
+ with open(NCDRILL_FILE) as f:
+ data = f.read()
+ settings = detect_excellon_format(data)
assert_equal(settings['format'], (2, 4))
assert_equal(settings['zeros'], 'trailing')
+ settings = detect_excellon_format(filename=NCDRILL_FILE)
+ assert_equal(settings['format'], (2, 4))
+ assert_equal(settings['zeros'], 'trailing')
+
+
def test_read():
ncdrill = read(NCDRILL_FILE)
assert(isinstance(ncdrill, ExcellonFile))
+
def test_write():
ncdrill = read(NCDRILL_FILE)
ncdrill.write('test.ncd')
with open(NCDRILL_FILE) as src:
- srclines = src.readlines()
-
+ srclines = src.readlines()
with open('test.ncd') as res:
- for idx, line in enumerate(res):
- assert_equal(line.strip(), srclines[idx].strip())
+ for idx, line in enumerate(res):
+ assert_equal(line.strip(), srclines[idx].strip())
os.remove('test.ncd')
+
def test_read_settings():
ncdrill = read(NCDRILL_FILE)
assert_equal(ncdrill.settings['format'], (2, 4))
assert_equal(ncdrill.settings['zeros'], 'trailing')
+
def test_bounds():
ncdrill = read(NCDRILL_FILE)
xbound, ybound = ncdrill.bounds
assert_array_almost_equal(xbound, (0.1300, 2.1430))
assert_array_almost_equal(ybound, (0.3946, 1.7164))
+
def test_report():
ncdrill = read(NCDRILL_FILE)
@@ -57,9 +67,7 @@ def test_conversion():
ncdrill_inch = copy.deepcopy(ncdrill)
ncdrill.to_metric()
assert_equal(ncdrill.settings.units, 'metric')
-
inch_primitives = ncdrill_inch.primitives
-
for tool in iter(ncdrill_inch.tools.values()):
tool.to_metric()
for primitive in inch_primitives:
@@ -80,26 +88,31 @@ def test_parser_hole_count():
p.parse(NCDRILL_FILE)
assert_equal(p.hole_count, 36)
+
def test_parser_hole_sizes():
settings = FileSettings(**detect_excellon_format(NCDRILL_FILE))
p = ExcellonParser(settings)
p.parse(NCDRILL_FILE)
assert_equal(p.hole_sizes, [0.0236, 0.0354, 0.04, 0.126, 0.128])
+
def test_parse_whitespace():
p = ExcellonParser(FileSettings())
assert_equal(p._parse(' '), None)
+
def test_parse_comment():
p = ExcellonParser(FileSettings())
p._parse(';A comment')
assert_equal(p.statements[0].comment, 'A comment')
+
def test_parse_format_comment():
p = ExcellonParser(FileSettings())
p._parse('; FILE_FORMAT=9:9 ')
assert_equal(p.format, (9, 9))
+
def test_parse_header():
p = ExcellonParser(FileSettings())
p._parse('M48 ')
@@ -107,6 +120,7 @@ def test_parse_header():
p._parse('M95 ')
assert_equal(p.state, 'DRILL')
+
def test_parse_rout():
p = ExcellonParser(FileSettings())
p._parse('G00 ')
@@ -114,6 +128,7 @@ def test_parse_rout():
p._parse('G05 ')
assert_equal(p.state, 'DRILL')
+
def test_parse_version():
p = ExcellonParser(FileSettings())
p._parse('VER,1 ')
@@ -121,6 +136,7 @@ def test_parse_version():
p._parse('VER,2 ')
assert_equal(p.statements[1].version, 2)
+
def test_parse_format():
p = ExcellonParser(FileSettings())
p._parse('FMAT,1 ')
@@ -128,6 +144,7 @@ def test_parse_format():
p._parse('FMAT,2 ')
assert_equal(p.statements[1].format, 2)
+
def test_parse_units():
settings = FileSettings(units='inch', zeros='trailing')
p = ExcellonParser(settings)
@@ -138,6 +155,7 @@ def test_parse_units():
assert_equal(p.units, 'metric')
assert_equal(p.zeros, 'leading')
+
def test_parse_incremental_mode():
settings = FileSettings(units='inch', zeros='trailing')
p = ExcellonParser(settings)
@@ -147,6 +165,7 @@ def test_parse_incremental_mode():
p._parse('ICI,OFF ')
assert_equal(p.notation, 'absolute')
+
def test_parse_absolute_mode():
settings = FileSettings(units='inch', zeros='trailing')
p = ExcellonParser(settings)
@@ -156,18 +175,21 @@ def test_parse_absolute_mode():
p._parse('G90 ')
assert_equal(p.notation, 'absolute')
+
def test_parse_repeat_hole():
p = ExcellonParser(FileSettings())
p.active_tool = ExcellonTool(FileSettings(), number=8)
p._parse('R03X1.5Y1.5')
assert_equal(p.statements[0].count, 3)
+
def test_parse_incremental_position():
p = ExcellonParser(FileSettings(notation='incremental'))
p._parse('X01Y01')
p._parse('X01Y01')
assert_equal(p.pos, [2.,2.])
+
def test_parse_unknown():
p = ExcellonParser(FileSettings())
p._parse('Not A Valid Statement')