summaryrefslogtreecommitdiff
path: root/gerber/tests/test_excellon_statements.py
blob: 2e508ff6505dfaff43dd714e41e3369693d2acd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Author: Hamilton Kibbe <ham@hamiltonkib.be>

from .tests import assert_equal, assert_raises
from ..excellon_statements import *
from ..cam import FileSettings


def test_excellontool_factory():
    """ Test ExcellonTool factory method
    """
    exc_line = 'T8F00S00C0.12500'
    settings = FileSettings(format=(2, 5), zero_suppression='trailing',
                units='inch', notation='absolute')
    tool = ExcellonTool.from_excellon(exc_line, settings)
    assert_equal(tool.diameter, 0.125)
    assert_equal(tool.feed_rate, 0)
    assert_equal(tool.rpm, 0)


def test_excellontool_dump():
    """ Test ExcellonTool to_excellon()
    """
    exc_lines = ['T01F0S0C0.01200', 'T02F0S0C0.01500', 'T03F0S0C0.01968',
                 'T04F0S0C0.02800', 'T05F0S0C0.03300', 'T06F0S0C0.03800',
                 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', ]
    settings = FileSettings(format=(2, 5), zero_suppression='trailing',
                units='inch', notation='absolute')
    for line in exc_lines:
        tool = ExcellonTool.from_excellon(line, settings)
        assert_equal(tool.to_excellon(), line)


def test_excellontool_order():
    settings = FileSettings(format=(2, 5), zero_suppression='trailing',
                units='inch', notation='absolute')
    line = 'T8F00S00C0.12500'
    tool1 = ExcellonTool.from_excellon(line, settings)
    line = 'T8C0.12500F00S00'
    tool2 = ExcellonTool.from_excellon(line, settings)
    assert_equal(tool1.diameter, tool2.diameter)
    assert_equal(tool1.feed_rate, tool2.feed_rate)
    assert_equal(tool1.rpm, tool2.rpm)


def test_toolselection_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_toolselection_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)


def test_coordinatestmt_factory():
    """ Test CoordinateStmt factory method
    """
    settings = FileSettings(format=(2, 5), zero_suppression='trailing',
                units='inch', notation='absolute')

    line = 'X0278207Y0065293'
    stmt = CoordinateStmt.from_excellon(line, settings)
    assert_equal(stmt.x, 2.78207)
    assert_equal(stmt.y, 0.65293)

    # line = 'X02945'
    # stmt = CoordinateStmt.from_excellon(line)
    # assert_equal(stmt.x, 2.945)

    # line = 'Y00575'
    # stmt = CoordinateStmt.from_excellon(line)
    # assert_equal(stmt.y, 0.575)

    settings = FileSettings(format=(2, 4), zero_suppression='leading',
                units='inch', notation='absolute')

    line = 'X9660Y4639'
    stmt = CoordinateStmt.from_excellon(line, settings)
    assert_equal(stmt.x, 0.9660)
    assert_equal(stmt.y, 0.4639)
    assert_equal(stmt.to_excellon(settings), "X9660Y4639")



def test_coordinatestmt_dump():
    """ Test CoordinateStmt to_excellon()
    """
    lines = ['X278207Y65293', 'X243795', 'Y82528', 'Y86028',
             'X251295Y81528', 'X2525Y78', 'X255Y575', 'Y52',
             'X2675', 'Y575', 'X2425', 'Y52', 'X23', ]

    settings = FileSettings(format=(2, 4), zero_suppression='leading',
                units='inch', notation='absolute')

    for line in lines:
        stmt = CoordinateStmt.from_excellon(line, settings)
        assert_equal(stmt.to_excellon(settings), line)


def test_commentstmt_factory():
    """ Test CommentStmt factory method
    """
    line = ';Layer_Color=9474304'
    stmt = CommentStmt.from_excellon(line)
    assert_equal(stmt.comment, line[1:])

    line = ';FILE_FORMAT=2:5'
    stmt = CommentStmt.from_excellon(line)
    assert_equal(stmt.comment, line[1:])

    line = ';TYPE=PLATED'
    stmt = CommentStmt.from_excellon(line)
    assert_equal(stmt.comment, line[1:])


def test_commentstmt_dump():
    """ Test CommentStmt to_excellon()
    """
    lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ]
    for line in lines:
        stmt = CommentStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_unitstmt_factory():
    """ Test UnitStmt factory method
    """
    line = 'INCH,LZ'
    stmt = UnitStmt.from_excellon(line)
    assert_equal(stmt.units, 'inch')
    assert_equal(stmt.zeros, 'leading')

    line = 'INCH,TZ'
    stmt = UnitStmt.from_excellon(line)
    assert_equal(stmt.units, 'inch')
    assert_equal(stmt.zeros, 'trailing')

    line = 'METRIC,LZ'
    stmt = UnitStmt.from_excellon(line)
    assert_equal(stmt.units, 'metric')
    assert_equal(stmt.zeros, 'leading')

    line = 'METRIC,TZ'
    stmt = UnitStmt.from_excellon(line)
    assert_equal(stmt.units, 'metric')
    assert_equal(stmt.zeros, 'trailing')


def test_unitstmt_dump():
    """ Test UnitStmt to_excellon()
    """
    lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ]
    for line in lines:
        stmt = UnitStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_incrementalmode_factory():
    """ Test IncrementalModeStmt factory method
    """
    line = 'ICI,ON'
    stmt = IncrementalModeStmt.from_excellon(line)
    assert_equal(stmt.mode, 'on')

    line = 'ICI,OFF'
    stmt = IncrementalModeStmt.from_excellon(line)
    assert_equal(stmt.mode, 'off')


def test_incrementalmode_dump():
    """ Test IncrementalModeStmt to_excellon()
    """
    lines = ['ICI,ON', 'ICI,OFF', ]
    for line in lines:
        stmt = IncrementalModeStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_incrementalmode_validation():
    """ Test IncrementalModeStmt input validation
    """
    assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH')


def test_versionstmt_factory():
    """ Test VersionStmt factory method
    """
    line = 'VER,1'
    stmt = VersionStmt.from_excellon(line)
    assert_equal(stmt.version, 1)

    line = 'VER,2'
    stmt = VersionStmt.from_excellon(line)
    assert_equal(stmt.version, 2)


def test_versionstmt_dump():
    """ Test VersionStmt to_excellon()
    """
    lines = ['VER,1', 'VER,2', ]
    for line in lines:
        stmt = VersionStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)

def test_versionstmt_validation():
    """ Test VersionStmt input validation
    """
    assert_raises(ValueError, VersionStmt, 3)


def test_formatstmt_factory():
    """ Test FormatStmt factory method
    """
    line = 'FMAT,1'
    stmt = FormatStmt.from_excellon(line)
    assert_equal(stmt.format, 1)

    line = 'FMAT,2'
    stmt = FormatStmt.from_excellon(line)
    assert_equal(stmt.format, 2)


def test_formatstmt_dump():
    """ Test FormatStmt to_excellon()
    """
    lines = ['FMAT,1', 'FMAT,2', ]
    for line in lines:
        stmt = FormatStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_formatstmt_validation():
    """ Test FormatStmt input validation
    """
    assert_raises(ValueError, FormatStmt, 3)


def test_linktoolstmt_factory():
    """ Test LinkToolStmt factory method
    """
    line = '1/2/3/4'
    stmt = LinkToolStmt.from_excellon(line)
    assert_equal(stmt.linked_tools, [1, 2, 3, 4])

    line = '01/02/03/04'
    stmt = LinkToolStmt.from_excellon(line)
    assert_equal(stmt.linked_tools, [1, 2, 3, 4])


def test_linktoolstmt_dump():
    """ Test LinkToolStmt to_excellon()
    """
    lines = ['1/2/3/4', '5/6/7', ]
    for line in lines:
        stmt = LinkToolStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_measmodestmt_factory():
    """ Test MeasuringModeStmt factory method
    """
    line = 'M72'
    stmt = MeasuringModeStmt.from_excellon(line)
    assert_equal(stmt.units, 'inch')

    line = 'M71'
    stmt = MeasuringModeStmt.from_excellon(line)
    assert_equal(stmt.units, 'metric')


def test_measmodestmt_dump():
    """ Test MeasuringModeStmt to_excellon()
    """
    lines = ['M71', 'M72', ]
    for line in lines:
        stmt = MeasuringModeStmt.from_excellon(line)
        assert_equal(stmt.to_excellon(), line)


def test_measmodestmt_validation():
    """ Test MeasuringModeStmt input validation
    """
    assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70')
    assert_raises(ValueError, MeasuringModeStmt, 'millimeters')