add tests
This commit is contained in:
parent
7f75e8b9e9
commit
f7c1939873
3 changed files with 73 additions and 26 deletions
|
|
@ -102,26 +102,42 @@ class ExcellonTool(ExcellonStatement):
|
||||||
commands = re.split('([BCFHSTZ])', line)[1:]
|
commands = re.split('([BCFHSTZ])', line)[1:]
|
||||||
commands = [(command, value) for command, value in pairwise(commands)]
|
commands = [(command, value) for command, value in pairwise(commands)]
|
||||||
args = {}
|
args = {}
|
||||||
format = settings['format']
|
nformat = settings['format']
|
||||||
zero_suppression = settings['zero_suppression']
|
zero_suppression = settings['zero_suppression']
|
||||||
for cmd, val in commands:
|
for cmd, val in commands:
|
||||||
if cmd == 'B':
|
if cmd == 'B':
|
||||||
args['retract_rate'] = parse_gerber_value(val, format, zero_suppression)
|
args['retract_rate'] = parse_gerber_value(val, nformat, zero_suppression)
|
||||||
elif cmd == 'C':
|
elif cmd == 'C':
|
||||||
args['diameter'] = parse_gerber_value(val, format, zero_suppression)
|
args['diameter'] = parse_gerber_value(val, nformat, zero_suppression)
|
||||||
elif cmd == 'F':
|
elif cmd == 'F':
|
||||||
args['feed_rate'] = parse_gerber_value(val, format, zero_suppression)
|
args['feed_rate'] = parse_gerber_value(val, nformat, zero_suppression)
|
||||||
elif cmd == 'H':
|
elif cmd == 'H':
|
||||||
args['max_hit_count'] = parse_gerber_value(val, format, zero_suppression)
|
args['max_hit_count'] = parse_gerber_value(val, nformat, zero_suppression)
|
||||||
elif cmd == 'S':
|
elif cmd == 'S':
|
||||||
args['rpm'] = 1000 * parse_gerber_value(val, format, zero_suppression)
|
args['rpm'] = 1000 * parse_gerber_value(val, nformat, zero_suppression)
|
||||||
elif cmd == 'T':
|
elif cmd == 'T':
|
||||||
args['number'] = int(val)
|
args['number'] = int(val)
|
||||||
elif cmd == 'Z':
|
elif cmd == 'Z':
|
||||||
args['depth_offset'] = parse_gerber_value(val, format, zero_suppression)
|
args['depth_offset'] = parse_gerber_value(val, nformat, zero_suppression)
|
||||||
return cls(settings, **args)
|
return cls(settings, **args)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def from_dict(cls, settings, tool_dict):
|
def from_dict(cls, settings, tool_dict):
|
||||||
|
""" Create an ExcellonTool from a dict.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
settings : FileSettings (dict-like)
|
||||||
|
Excellon File-wide settings
|
||||||
|
|
||||||
|
tool_dict : dict
|
||||||
|
Excellon tool parameters as a dict
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
tool : ExcellonTool
|
||||||
|
An ExcellonTool initialized with the parameters in tool_dict.
|
||||||
|
"""
|
||||||
return cls(settings, tool_dict)
|
return cls(settings, tool_dict)
|
||||||
|
|
||||||
def __init__(self, settings, **kwargs):
|
def __init__(self, settings, **kwargs):
|
||||||
|
|
@ -168,6 +184,18 @@ class ToolSelectionStmt(ExcellonStatement):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_excellon(cls, line):
|
def from_excellon(cls, line):
|
||||||
|
""" Create a ToolSelectionStmt from an excellon file line.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
line : string
|
||||||
|
Line from an Excellon file
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
tool_statement : ToolSelectionStmt
|
||||||
|
ToolSelectionStmt representation of `line.`
|
||||||
|
"""
|
||||||
line = line.strip()[1:]
|
line = line.strip()[1:]
|
||||||
compensation_index = None
|
compensation_index = None
|
||||||
tool = int(line[:2])
|
tool = int(line[:2])
|
||||||
|
|
@ -177,7 +205,8 @@ class ToolSelectionStmt(ExcellonStatement):
|
||||||
|
|
||||||
def __init__(self, tool, compensation_index=None):
|
def __init__(self, tool, compensation_index=None):
|
||||||
tool = int(tool)
|
tool = int(tool)
|
||||||
compensation_index = int(compensation_index) if compensation_index else None
|
compensation_index = (int(compensation_index) if compensation_index
|
||||||
|
is not None else None)
|
||||||
self.tool = tool
|
self.tool = tool
|
||||||
self.compensation_index = compensation_index
|
self.compensation_index = compensation_index
|
||||||
|
|
||||||
|
|
@ -191,16 +220,16 @@ class ToolSelectionStmt(ExcellonStatement):
|
||||||
class CoordinateStmt(ExcellonStatement):
|
class CoordinateStmt(ExcellonStatement):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_excellon(cls, line, format=(2, 5), zero_suppression='trailing'):
|
def from_excellon(cls, line, nformat=(2, 5), zero_suppression='trailing'):
|
||||||
x = None
|
x = None
|
||||||
y = None
|
y = None
|
||||||
if line[0] == 'X':
|
if line[0] == 'X':
|
||||||
splitline = line.strip('X').split('Y')
|
splitline = line.strip('X').split('Y')
|
||||||
x = parse_gerber_value(splitline[0].strip(), format, zero_suppression)
|
x = parse_gerber_value(splitline[0].strip(), nformat, zero_suppression)
|
||||||
if len(splitline) == 2:
|
if len(splitline) == 2:
|
||||||
y = parse_gerber_value(splitline[1].strip(), format, zero_suppression)
|
y = parse_gerber_value(splitline[1].strip(), nformat, zero_suppression)
|
||||||
else:
|
else:
|
||||||
y = parse_gerber_value(line.strip(' Y'), format, zero_suppression)
|
y = parse_gerber_value(line.strip(' Y'), nformat, zero_suppression)
|
||||||
return cls(x, y)
|
return cls(x, y)
|
||||||
|
|
||||||
def __init__(self, x=None, y=None):
|
def __init__(self, x=None, y=None):
|
||||||
|
|
@ -270,6 +299,7 @@ class EndOfProgramStmt(ExcellonStatement):
|
||||||
stmt += 'Y%s' % write_gerber_value(self.y)
|
stmt += 'Y%s' % write_gerber_value(self.y)
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
|
|
||||||
class UnitStmt(ExcellonStatement):
|
class UnitStmt(ExcellonStatement):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -288,6 +318,7 @@ class UnitStmt(ExcellonStatement):
|
||||||
else 'TZ')
|
else 'TZ')
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
|
|
||||||
class IncrementalModeStmt(ExcellonStatement):
|
class IncrementalModeStmt(ExcellonStatement):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -327,14 +358,14 @@ class FormatStmt(ExcellonStatement):
|
||||||
fmt = int(line.split(',')[1])
|
fmt = int(line.split(',')[1])
|
||||||
return cls(fmt)
|
return cls(fmt)
|
||||||
|
|
||||||
def __init__(self, format=1):
|
def __init__(self, nformat=1):
|
||||||
format = int(format)
|
nformat = int(nformat)
|
||||||
if format not in [1, 2]:
|
if nformat not in [1, 2]:
|
||||||
raise ValueError('Valid formats are 1 or 2')
|
raise ValueError('Valid formats are 1 or 2')
|
||||||
self.format = format
|
self.nformat = nformat
|
||||||
|
|
||||||
def to_excellon(self):
|
def to_excellon(self):
|
||||||
return 'FMAT,%d' % self.format
|
return 'FMAT,%d' % self.n
|
||||||
|
|
||||||
|
|
||||||
class LinkToolStmt(ExcellonStatement):
|
class LinkToolStmt(ExcellonStatement):
|
||||||
|
|
@ -380,8 +411,6 @@ class UnknownStmt(ExcellonStatement):
|
||||||
return self.stmt
|
return self.stmt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pairwise(iterator):
|
def pairwise(iterator):
|
||||||
""" Iterate over list taking two elements at a time.
|
""" Iterate over list taking two elements at a time.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def test_ExcellonTool_factory():
|
||||||
|
|
||||||
|
|
||||||
def test_ExcellonTool_dump():
|
def test_ExcellonTool_dump():
|
||||||
""" Test ExcellonTool to_gerber method
|
""" Test ExcellonTool to_excellon()
|
||||||
"""
|
"""
|
||||||
exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968',
|
exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968',
|
||||||
'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800',
|
'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800',
|
||||||
|
|
@ -31,3 +31,22 @@ def test_ExcellonTool_dump():
|
||||||
tool = ExcellonTool.from_excellon(line, settings)
|
tool = ExcellonTool.from_excellon(line, settings)
|
||||||
assert_equal(tool.to_excellon(), line)
|
assert_equal(tool.to_excellon(), line)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ToolSelectionStmt_factory():
|
||||||
|
""" Test ToolSelectionStmt factory method
|
||||||
|
"""
|
||||||
|
stmt = ToolSelectionStmt.from_excellon('T01')
|
||||||
|
assert_equal(stmt.tool, 1)
|
||||||
|
assert_equal(stmt.compensation_index, None)
|
||||||
|
stmt = ToolSelectionStmt.from_excellon('T0223')
|
||||||
|
assert_equal(stmt.tool, 2)
|
||||||
|
assert_equal(stmt.compensation_index, 23)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ToolSelectionStmt_dump():
|
||||||
|
""" Test ToolSelectionStmt to_excellon()
|
||||||
|
"""
|
||||||
|
lines = ['T01', 'T0223', 'T10', 'T09', 'T0000']
|
||||||
|
for line in lines:
|
||||||
|
stmt = ToolSelectionStmt.from_excellon(line)
|
||||||
|
assert_equal(stmt.to_excellon(), line)
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ def test_IPParamStmt_dump():
|
||||||
def test_OFParamStmt_factory():
|
def test_OFParamStmt_factory():
|
||||||
""" Test OFParamStmt factory correctly handles parameters
|
""" Test OFParamStmt factory correctly handles parameters
|
||||||
"""
|
"""
|
||||||
stmt = {'param': 'OF', 'a': '0.1234567', 'b':'0.1234567'}
|
stmt = {'param': 'OF', 'a': '0.1234567', 'b': '0.1234567'}
|
||||||
of = OFParamStmt.from_dict(stmt)
|
of = OFParamStmt.from_dict(stmt)
|
||||||
assert_equal(of.a, 0.1234567)
|
assert_equal(of.a, 0.1234567)
|
||||||
assert_equal(of.b, 0.1234567)
|
assert_equal(of.b, 0.1234567)
|
||||||
|
|
@ -102,4 +102,3 @@ def test_OFParamStmt_dump():
|
||||||
stmt = {'param': 'OF', 'a': '0.1234567', 'b': '0.1234567'}
|
stmt = {'param': 'OF', 'a': '0.1234567', 'b': '0.1234567'}
|
||||||
of = OFParamStmt.from_dict(stmt)
|
of = OFParamStmt.from_dict(stmt)
|
||||||
assert_equal(of.to_gerber(), '%OFA0.123456B0.123456*%')
|
assert_equal(of.to_gerber(), '%OFA0.123456B0.123456*%')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue