diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-05-16 09:45:34 -0400 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-05-16 09:45:34 -0400 |
commit | 8ec3077be988681bbbafcef18ea3a2f84dd61b2b (patch) | |
tree | 97b108fe6ca1d128420f58360f9976a3ca0ee0f0 /gerber | |
parent | 21d963d244cbc762a736527b25cd8e82ff147f25 (diff) | |
download | gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.tar.gz gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.tar.bz2 gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.zip |
Add checks to ensure statement unit conversions are idempotent
Diffstat (limited to 'gerber')
-rwxr-xr-x | gerber/excellon.py | 3 | ||||
-rw-r--r-- | gerber/excellon_statements.py | 80 | ||||
-rw-r--r-- | gerber/gerber_statements.py | 113 | ||||
-rw-r--r-- | gerber/rs274x.py | 4 | ||||
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 116 | ||||
-rw-r--r-- | gerber/tests/test_gerber_statements.py | 152 |
6 files changed, 379 insertions, 89 deletions
diff --git a/gerber/excellon.py b/gerber/excellon.py index 0f70de7..f994b67 100755 --- a/gerber/excellon.py +++ b/gerber/excellon.py @@ -219,6 +219,9 @@ class ExcellonParser(object): with open(filename, 'r') as f:
for line in f:
self._parse(line.strip())
+
+ for stmt in self.statements:
+ stmt.units = self.units
return ExcellonFile(self.statements, self.tools, self.hits,
self._settings(), filename)
diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py index 95347d1..31a3c72 100644 --- a/gerber/excellon_statements.py +++ b/gerber/excellon_statements.py @@ -39,6 +39,9 @@ __all__ = ['ExcellonTool', 'ToolSelectionStmt', 'CoordinateStmt', class ExcellonStatement(object): """ Excellon Statement abstract base class """ + + units = 'inch' + @classmethod def from_excellon(cls, line): raise NotImplementedError('from_excellon must be implemented in a ' @@ -47,12 +50,11 @@ class ExcellonStatement(object): def to_excellon(self, settings=None): raise NotImplementedError('to_excellon must be implemented in a ' 'subclass') - def to_inch(self): - pass + self.units = 'inch' def to_metric(self): - pass + self.units = 'metric' def offset(self, x_offset=0, y_offset=0): pass @@ -274,7 +276,9 @@ class CoordinateStmt(ExcellonStatement): else: y_coord = parse_gerber_value(line.strip(' Y'), settings.format, settings.zero_suppression) - return cls(x_coord, y_coord) + c = cls(x_coord, y_coord) + c.units = settings.units + return c def __init__(self, x=None, y=None): self.x = x @@ -291,16 +295,20 @@ class CoordinateStmt(ExcellonStatement): return stmt def to_inch(self): - if self.x is not None: - self.x = inch(self.x) - if self.y is not None: - self.y = inch(self.y) + if self.units == 'metric': + self.units = 'inch' + if self.x is not None: + self.x = inch(self.x) + if self.y is not None: + self.y = inch(self.y) def to_metric(self): - if self.x is not None: - self.x = metric(self.x) - if self.y is not None: - self.y = metric(self.y) + if self.units == 'inch': + self.units = 'metric' + if self.x is not None: + self.x = metric(self.x) + if self.y is not None: + self.y = metric(self.y) def offset(self, x_offset=0, y_offset=0): if self.x is not None: @@ -332,7 +340,9 @@ class RepeatHoleStmt(ExcellonStatement): ydelta = (parse_gerber_value(stmt['ydelta'], settings.format, settings.zero_suppression) if stmt['ydelta'] is not '' else None) - return cls(count, xdelta, ydelta) + c = cls(count, xdelta, ydelta) + c.units = settings.units + return c def __init__(self, count, xdelta=0.0, ydelta=0.0): self.count = count @@ -350,16 +360,20 @@ class RepeatHoleStmt(ExcellonStatement): return stmt def to_inch(self): - if self.xdelta is not None: - self.xdelta = inch(self.xdelta) - if self.ydelta is not None: - self.ydelta = inch(self.ydelta) + if self.units == 'metric': + self.units = 'inch' + if self.xdelta is not None: + self.xdelta = inch(self.xdelta) + if self.ydelta is not None: + self.ydelta = inch(self.ydelta) def to_metric(self): - if self.xdelta is not None: - self.xdelta = metric(self.xdelta) - if self.ydelta is not None: - self.ydelta = metric(self.ydelta) + if self.units == 'inch': + self.units = 'metric' + if self.xdelta is not None: + self.xdelta = metric(self.xdelta) + if self.ydelta is not None: + self.ydelta = metric(self.ydelta) def __str__(self): return '<Repeat Hole: %d times, offset X: %g Y: %g>' % ( @@ -421,7 +435,9 @@ class EndOfProgramStmt(ExcellonStatement): y = (parse_gerber_value(stmt['y'], settings.format, settings.zero_suppression) if stmt['y'] is not '' else None) - return cls(x, y) + c = cls(x, y) + c.units = settings.units + return c def __init__(self, x=None, y=None): self.x = x @@ -436,16 +452,20 @@ class EndOfProgramStmt(ExcellonStatement): return stmt def to_inch(self): - if self.x is not None: - self.x = inch(self.x) - if self.y is not None: - self.y = inch(self.y) + if self.units == 'metric': + self.units = 'inch' + if self.x is not None: + self.x = inch(self.x) + if self.y is not None: + self.y = inch(self.y) def to_metric(self): - if self.x is not None: - self.x = metric(self.x) - if self.y is not None: - self.y = metric(self.y) + if self.units == 'inch': + self.units = 'metric' + if self.x is not None: + self.x = metric(self.x) + if self.y is not None: + self.y = metric(self.y) def offset(self, x_offset=0, y_offset=0): if self.x is not None: diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index f2fc970..a198bb9 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -43,8 +43,9 @@ class Statement(object): type : string String identifying the statement type. """ - def __init__(self, stype): + def __init__(self, stype, units='inch'): self.type = stype + self.units = units def __str__(self): s = "<{0} ".format(self.__class__.__name__) @@ -56,10 +57,10 @@ class Statement(object): return s def to_inch(self): - pass + self.units = 'inch' def to_metric(self): - pass + self.units = 'metric' def offset(self, x_offset=0, y_offset=0): pass @@ -156,6 +157,8 @@ class FSParamStmt(ParamStmt): return '%FS{0}{1}X{2}Y{3}*%'.format(zero_suppression, notation, fmt, fmt) + + def __str__(self): return ('<Format Spec: %d:%d %s zero suppression %s notation>' % (self.format[0], self.format[1], self.zero_suppression, self.notation)) @@ -295,10 +298,14 @@ class ADParamStmt(ParamStmt): self.modifiers = [tuple()] def to_inch(self): - self.modifiers = [tuple([inch(x) for x in modifier]) for modifier in self.modifiers] + if self.units == 'metric': + self.units = 'inch' + self.modifiers = [tuple([inch(x) for x in modifier]) for modifier in self.modifiers] def to_metric(self): - self.modifiers = [tuple([metric(x) for x in modifier]) for modifier in self.modifiers] + if self.units == 'inch': + self.units = 'metric' + self.modifiers = [tuple([metric(x) for x in modifier]) for modifier in self.modifiers] def to_gerber(self, settings=None): if any(self.modifiers): @@ -383,12 +390,16 @@ class AMParamStmt(ParamStmt): self.primitives.append(AMUnsupportPrimitive.from_gerber(primitive)) def to_inch(self): - for primitive in self.primitives: - primitive.to_inch() + if self.units == 'metric': + self.units = 'inch' + for primitive in self.primitives: + primitive.to_inch() def to_metric(self): - for primitive in self.primitives: - primitive.to_metric() + if self.units == 'inch': + self.units = 'metric' + for primitive in self.primitives: + primitive.to_metric() def to_gerber(self, settings=None): return '%AM{0}*{1}*%'.format(self.name, self.macro) @@ -630,16 +641,20 @@ class OFParamStmt(ParamStmt): return ret + '*%' def to_inch(self): - if self.a is not None: - self.a = inch(self.a) - if self.b is not None: - self.b = inch(self.b) + if self.units == 'metric': + self.units = 'inch' + if self.a is not None: + self.a = inch(self.a) + if self.b is not None: + self.b = inch(self.b) def to_metric(self): - if self.a is not None: - self.a = metric(self.a) - if self.b is not None: - self.b = metric(self.b) + if self.units == 'inch': + self.units = 'metric' + if self.a is not None: + self.a = metric(self.a) + if self.b is not None: + self.b = metric(self.b) def offset(self, x_offset=0, y_offset=0): if self.a is not None: @@ -700,16 +715,20 @@ class SFParamStmt(ParamStmt): return ret + '*%' def to_inch(self): - if self.a is not None: - self.a = inch(self.a) - if self.b is not None: - self.b = inch(self.b) + if self.units == 'metric': + self.units = 'inch' + if self.a is not None: + self.a = inch(self.a) + if self.b is not None: + self.b = inch(self.b) def to_metric(self): - if self.a is not None: - self.a = metric(self.a) - if self.b is not None: - self.b = metric(self.b) + if self.units == 'inch': + self.units = 'metric' + if self.a is not None: + self.a = metric(self.a) + if self.b is not None: + self.b = metric(self.b) def offset(self, x_offset=0, y_offset=0): if self.a is not None: @@ -871,28 +890,32 @@ class CoordStmt(Statement): return ret + '*' def to_inch(self): - if self.x is not None: - self.x = inch(self.x) - if self.y is not None: - self.y = inch(self.y) - if self.i is not None: - self.i = inch(self.i) - if self.j is not None: - self.j = inch(self.j) - if self.function == "G71": - self.function = "G70" + if self.units == 'metric': + self.units = 'inch' + if self.x is not None: + self.x = inch(self.x) + if self.y is not None: + self.y = inch(self.y) + if self.i is not None: + self.i = inch(self.i) + if self.j is not None: + self.j = inch(self.j) + if self.function == "G71": + self.function = "G70" def to_metric(self): - if self.x is not None: - self.x = metric(self.x) - if self.y is not None: - self.y = metric(self.y) - if self.i is not None: - self.i = metric(self.i) - if self.j is not None: - self.j = metric(self.j) - if self.function == "G70": - self.function = "G71" + if self.units == 'inch': + self.units = 'metric' + if self.x is not None: + self.x = metric(self.x) + if self.y is not None: + self.y = metric(self.y) + if self.i is not None: + self.i = metric(self.i) + if self.j is not None: + self.j = metric(self.j) + if self.function == "G70": + self.function = "G71" def offset(self, x_offset=0, y_offset=0): if self.x is not None: diff --git a/gerber/rs274x.py b/gerber/rs274x.py index 3dcddb4..20baaa7 100644 --- a/gerber/rs274x.py +++ b/gerber/rs274x.py @@ -214,6 +214,10 @@ class GerberParser(object): self.evaluate(stmt) self.statements.append(stmt) + # Initialize statement units + for stmt in self.statements: + stmt.units = self.settings.units + return GerberFile(self.statements, self.settings, self.primitives, filename) def dump_json(self): diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index ada5194..1e8ef91 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -150,7 +150,13 @@ def test_coordinatestmt_factory(): assert_equal(stmt.x, 0.9660) assert_equal(stmt.y, 0.4639) assert_equal(stmt.to_excellon(settings), "X9660Y4639") - + assert_equal(stmt.units, 'inch') + + settings.units = 'metric' + stmt = CoordinateStmt.from_excellon(line, settings) + assert_equal(stmt.units, 'metric') + + def test_coordinatestmt_dump(): """ Test CoordinateStmt to_excellon() """ @@ -164,11 +170,40 @@ def test_coordinatestmt_dump(): assert_equal(stmt.to_excellon(settings), line) def test_coordinatestmt_conversion(): - stmt = CoordinateStmt.from_excellon('X254Y254', FileSettings()) + + settings = FileSettings() + settings.units = 'metric' + stmt = CoordinateStmt.from_excellon('X254Y254', settings) + + #No effect + stmt.to_metric() + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 25.4) + stmt.to_inch() + assert_equal(stmt.units, 'inch') assert_equal(stmt.x, 1.) assert_equal(stmt.y, 1.) - stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 1.) + + settings.units = 'inch' + stmt = CoordinateStmt.from_excellon('X01Y01', settings) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 1.) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 25.4) + + #No effect stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 25.4) @@ -194,10 +229,14 @@ def test_coordinatestmt_string(): def test_repeathole_stmt_factory(): - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading')) + stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='inch')) assert_equal(stmt.count, 4) assert_equal(stmt.xdelta, 1.5) assert_equal(stmt.ydelta, 32) + assert_equal(stmt.units, 'inch') + + stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='metric')) + assert_equal(stmt.units, 'metric') def test_repeatholestmt_dump(): line = 'R4X015Y32' @@ -206,13 +245,40 @@ def test_repeatholestmt_dump(): def test_repeatholestmt_conversion(): line = 'R4X0254Y254' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #No effect + stmt.to_metric() + assert_equal(stmt.xdelta, 2.54) + assert_equal(stmt.ydelta, 25.4) + + stmt.to_inch() + assert_equal(stmt.units, 'inch') + assert_equal(stmt.xdelta, 0.1) + assert_equal(stmt.ydelta, 1.) + + #no effect stmt.to_inch() assert_equal(stmt.xdelta, 0.1) assert_equal(stmt.ydelta, 1.) line = 'R4X01Y1' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings.units = 'inch' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #no effect + stmt.to_inch() + assert_equal(stmt.xdelta, 1.) + assert_equal(stmt.ydelta, 10.) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.xdelta, 25.4) + assert_equal(stmt.ydelta, 254.) + + #No effect stmt.to_metric() assert_equal(stmt.xdelta, 25.4) assert_equal(stmt.ydelta, 254.) @@ -258,12 +324,16 @@ def test_rewindstop_stmt(): assert_equal(stmt.to_excellon(None), '%') def test_endofprogramstmt_factory(): - stmt = EndOfProgramStmt.from_excellon('M30X01Y02', FileSettings()) + settings = FileSettings(units='inch') + stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, 2.) - stmt = EndOfProgramStmt.from_excellon('M30X01', FileSettings()) + assert_equal(stmt.units, 'inch') + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X01', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, None) + assert_equal(stmt.units, 'metric') stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) assert_equal(stmt.x, None) assert_equal(stmt.y, 2.) @@ -275,12 +345,38 @@ def test_endofprogramStmt_dump(): assert_equal(stmt.to_excellon(FileSettings()), line) def test_endofprogramstmt_conversion(): - stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings) + #No effect + stmt.to_metric() + assert_equal(stmt.x, 2.54) + assert_equal(stmt.y, 25.4) + + stmt.to_inch() + assert_equal(stmt.units, 'inch') + assert_equal(stmt.x, 0.1) + assert_equal(stmt.y, 1.0) + + #No effect stmt.to_inch() assert_equal(stmt.x, 0.1) assert_equal(stmt.y, 1.0) - stmt = EndOfProgramStmt.from_excellon('M30X01Y1', FileSettings()) + settings.units = 'inch' + stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 10.0) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 254.) + + #No effect stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 254.) diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index a8a4a1a..f3249b1 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -10,10 +10,13 @@ from ..cam import FileSettings def test_Statement_smoketest(): stmt = Statement('Test') assert_equal(stmt.type, 'Test') + stmt.to_metric() + assert_in('units=metric', str(stmt)) stmt.to_inch() + assert_in('units=inch', str(stmt)) stmt.to_metric() stmt.offset(1, 1) - assert_equal(str(stmt), '<Statement type=Test>') + assert_in('type=Test',str(stmt)) def test_FSParamStmt_factory(): """ Test FSParamStruct factory @@ -220,12 +223,38 @@ def test_OFParamStmt_dump(): def test_OFParamStmt_conversion(): stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} of = OFParamStmt.from_dict(stmt) + of.units='metric' + + # No effect + of.to_metric() + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + of.to_inch() + assert_equal(of.units, 'inch') + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + #No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} of = OFParamStmt.from_dict(stmt) + of.units = 'inch' + + #No effect + of.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + of.to_metric() + assert_equal(of.units, 'metric') + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + #No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) @@ -261,12 +290,38 @@ def test_SFParamStmt_dump(): def test_SFParamStmt_conversion(): stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} of = SFParamStmt.from_dict(stmt) + of.units = 'metric' + of.to_metric() + + #No effect + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + of.to_inch() + assert_equal(of.units, 'inch') + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + #No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} of = SFParamStmt.from_dict(stmt) + of.units = 'inch' + + #No effect + of.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + of.to_metric() + assert_equal(of.units, 'metric') + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + #No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) @@ -350,7 +405,21 @@ def testAMParamStmt_conversion(): name = 'POLYGON' macro = '5,1,8,25.4,25.4,25.4,0*' s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s.build() + s.units = 'metric' + + #No effect + s.to_metric() + assert_equal(s.primitives[0].position, (25.4, 25.4)) + assert_equal(s.primitives[0].diameter, 25.4) + + s.to_inch() + assert_equal(s.units, 'inch') + assert_equal(s.primitives[0].position, (1., 1.)) + assert_equal(s.primitives[0].diameter, 1.) + + #No effect s.to_inch() assert_equal(s.primitives[0].position, (1., 1.)) assert_equal(s.primitives[0].diameter, 1.) @@ -358,6 +427,19 @@ def testAMParamStmt_conversion(): macro = '5,1,8,1,1,1,0*' s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) s.build() + s.units = 'inch' + + #No effect + s.to_inch() + assert_equal(s.primitives[0].position, (1., 1.)) + assert_equal(s.primitives[0].diameter, 1.) + + s.to_metric() + assert_equal(s.units, 'metric') + assert_equal(s.primitives[0].position, (25.4, 25.4)) + assert_equal(s.primitives[0].diameter, 25.4) + + #No effect s.to_metric() assert_equal(s.primitives[0].position, (25.4, 25.4)) assert_equal(s.primitives[0].diameter, 25.4) @@ -535,10 +617,10 @@ def test_statement_string(): """ Test Statement.__str__() """ stmt = Statement('PARAM') - assert_equal(str(stmt), '<Statement type=PARAM>') + assert_in('type=PARAM', str(stmt)) stmt.test='PASS' - assert_true('test=PASS' in str(stmt)) - assert_true('type=PARAM' in str(stmt)) + assert_in('test=PASS', str(stmt)) + assert_in('type=PARAM', str(stmt)) def test_ADParamStmt_factory(): """ Test ADParamStmt factory @@ -556,12 +638,37 @@ def test_ADParamStmt_factory(): def test_ADParamStmt_conversion(): stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '25.4X25.4,25.4X25.4'} ad = ADParamStmt.from_dict(stmt) + ad.units = 'metric' + + #No effect + ad.to_metric() + assert_equal(ad.modifiers[0], (25.4, 25.4)) + assert_equal(ad.modifiers[1], (25.4, 25.4)) + + ad.to_inch() + assert_equal(ad.units, 'inch') + assert_equal(ad.modifiers[0], (1., 1.)) + assert_equal(ad.modifiers[1], (1., 1.)) + + #No effect ad.to_inch() assert_equal(ad.modifiers[0], (1., 1.)) assert_equal(ad.modifiers[1], (1., 1.)) stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '1X1,1X1'} ad = ADParamStmt.from_dict(stmt) + ad.units = 'inch' + + #No effect + ad.to_inch() + assert_equal(ad.modifiers[0], (1., 1.)) + assert_equal(ad.modifiers[1], (1., 1.)) + + ad.to_metric() + assert_equal(ad.modifiers[0], (25.4, 25.4)) + assert_equal(ad.modifiers[1], (25.4, 25.4)) + + #No effect ad.to_metric() assert_equal(ad.modifiers[0], (25.4, 25.4)) assert_equal(ad.modifiers[1], (25.4, 25.4)) @@ -646,6 +753,25 @@ def test_coordstmt_dump(): def test_coordstmt_conversion(): cs = CoordStmt('G71', 25.4, 25.4, 25.4, 25.4, 'D01', FileSettings()) + cs.units = 'metric' + + #No effect + cs.to_metric() + assert_equal(cs.x, 25.4) + assert_equal(cs.y, 25.4) + assert_equal(cs.i, 25.4) + assert_equal(cs.j, 25.4) + assert_equal(cs.function, 'G71') + + cs.to_inch() + assert_equal(cs.units, 'inch') + assert_equal(cs.x, 1.) + assert_equal(cs.y, 1.) + assert_equal(cs.i, 1.) + assert_equal(cs.j, 1.) + assert_equal(cs.function, 'G70') + + #No effect cs.to_inch() assert_equal(cs.x, 1.) assert_equal(cs.y, 1.) @@ -654,6 +780,24 @@ def test_coordstmt_conversion(): assert_equal(cs.function, 'G70') cs = CoordStmt('G70', 1., 1., 1., 1., 'D01', FileSettings()) + cs.units = 'inch' + + #No effect + cs.to_inch() + assert_equal(cs.x, 1.) + assert_equal(cs.y, 1.) + assert_equal(cs.i, 1.) + assert_equal(cs.j, 1.) + assert_equal(cs.function, 'G70') + + cs.to_metric() + assert_equal(cs.x, 25.4) + assert_equal(cs.y, 25.4) + assert_equal(cs.i, 25.4) + assert_equal(cs.j, 25.4) + assert_equal(cs.function, 'G71') + + #No effect cs.to_metric() assert_equal(cs.x, 25.4) assert_equal(cs.y, 25.4) |